我用以下代码向163相册上传图片,经抓包,发出的信息没有发送完,只发了一半,请问问题出在哪里?
Private Sub Command1_Click()
Me.Winsock1.RemoteHost = "upload.photo.163.com"
Me.Winsock1.RemotePort = 80
Me.Winsock1.Connect
Me.Label1 = "Connecting..."
DoEvents
tmr = Timer
Do Until Me.Winsock1.State = 7
DoEvents
If Timer - tmr >= 10 Then
MsgBox "Connection Timeout.", vbOKOnly, "Error"
Me.Winsock1.Close
Exit Sub
End If
Loop
Me.Label1 = "Ready to send..."
strhttpheader = strhttpheader & "POST /AppUpload.do?ApiName=uploadPhoto HTTP/1.1" & vbCrLf
strhttpheader = strhttpheader & "Referer: upload.photo.163.com" & vbCrLf
strhttpheader = strhttpheader & "Accept: text/*" & vbCrLf
strhttpheader = strhttpheader & "Content-Type: multipart/form-data; boundary=---------------------------7d61194b027e" & vbCrLf
strhttpheader = strhttpheader & "User-Agent: 163UPL~1" & vbCrLf
strhttpheader = strhttpheader & "Host: upload.photo.163.com" & vbCrLf
strhttpheader = strhttpheader & "Cookie: NTES_SESS=fXNzykyeaEePXDtluFzgDZhIAZreEDSvZBDejdd1XrELRfAyoR3AD04hbzaL28FE6gy6R2Jw0uhyy50L9atbMp5pR; _ntes_nvst=1177017267156,|photo|; PSESSIONID=AD876049F3F3404A2BE7F660DAE65E4D.upload-8; NETEASE_SSN=amdlcom; NETEASE_ADV=11&23&1177042318041; ntesAds2781vichy=photo2782logo:97,17200,0,0,0,0,0,0&photo2782duilianb:2,35,0,NaN,0,1,0,0; _ntes_nvid=c15811bbae5405c2dca74a63d1aebd90; _ntes_nnsit=|photo|research|urs|stock|; _ntes_is_survey=photo; MAIL163_SSN=amdlcom; theaddr=%u6E56%u5357; ntesAds2800lancome=photo2800logob:3,15,0,0,0,0,0,0; hitcounter=amdlcom" & vbCrLf & vbCrLf
'strhttpheader = strhttpheader & "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)" & vbCrLf
'strhttpheader = strhttpheader & "Connection: Keep-Alive" & vbCrLf
'strhttpheader = strhttpheader & "Cache-Control: no-cache" & vbCrLf
strbody = strbody & "---------------------------7d61194b027e" & vbCrLf
strbody = strbody & "Content-Disposition:form-data;name=""albumId""" & vbCrLf & vbCrLf
'strbody = strbody & "" & vbCrLf
strbody = strbody & "121357160" & vbCrLf
strbody = strbody & "---------------------------7d61194b027e" & vbCrLf
strbody = strbody & "Content-Disposition:form-data;name=""sid""" & vbCrLf & vbCrLf
' strbody = strbody & "" & vbCrLf
strbody = strbody & "TVRFM056QTBPRFUwTXc9PQ==" & vbCrLf & vbCrLf
strbody = strbody & "---------------------------7d61194b027e" & vbCrLf
strbody = strbody & "Content-Disposition:form-data;name=""OriginDim""" & vbCrLf & vbCrLf
'strbody = strbody & "" & vbCrLf
strbody = strbody & "80;80" & vbCrLf
strbody = strbody & "---------------------------7d61194b027e" & vbCrLf
strbody = strbody & "Content-Disposition: form-data; name=""OriginFile"";filename=""" & Me.Text1 & """" & vbCrLf
'strbody = strbody & "Content-Type: application/octet-stream" & vbCrLf
strbody = strbody & "Content-Type: image/jpeg" & vbCrLf & vbCrLf
'strbody = strbody & "" & vbCrLf
strbody2 = "---------------------------7d61194b027e" & vbCrLf
strbody2 = strbody2 & "Content-Disposition:form-data;name=""SmallerDim""" & vbCrLf & vbCrLf
'strbody2 = strbody2 & "" & vbCrLf
strbody2 = strbody2 & "80;80" & vbCrLf
strbody2 = strbody2 & "---------------------------7d61194b027e" & vbCrLf & vbCrLf
strbody2 = strbody2 & "Content-Disposition: form-data; name=""SmallerFile"";filename=""$$_ORIGIN_$$"" & vbCrLf"
strbody2 = strbody2 & "Content-Type: image/jpeg" & vbCrLf & vbCrLf & vbCrLf
strbody2 = strbody2 & "---------------------------7d61194b027e--" & vbCrLf & vbCrLf
strhttpheader = strhttpheader & "Content-Length: " & CLng(Len(strbody) + Len(strbody2) + FileLen(Me.Text1)) & vbCrLf & vbCrLf
Me.Winsock1.SendData strhttpheader & strbody
DoEvents
Me.Label1 = "Sending file data..."
DoEvents
Dim bytBuff(8191) As Byte
Dim bytRem() As Byte
Open Me.Text1.Text For Binary As #1
times = Int(LOF(1) / 8192)
ReDim bytRem(LOF(1) Mod 8192 - 1)
For i = 1 To times
Get #1, , bytBuff
Me.Winsock1.SendData bytBuff
DoEvents
Next
Get #1, , bytRem
Me.Winsock1.SendData bytRem
DoEvents
Close #1
Me.Winsock1.SendData vbCrLf & strbody2
DoEvents
Me.Label1 = "File was sent successfully."
DoEvents
Me.Winsock1.Close
End Sub
Private Sub Command1_Click()
Me.Winsock1.RemoteHost = "upload.photo.163.com"
Me.Winsock1.RemotePort = 80
Me.Winsock1.Connect
Me.Label1 = "Connecting..."
DoEvents
tmr = Timer
Do Until Me.Winsock1.State = 7
DoEvents
If Timer - tmr >= 10 Then
MsgBox "Connection Timeout.", vbOKOnly, "Error"
Me.Winsock1.Close
Exit Sub
End If
Loop
Me.Label1 = "Ready to send..."
strhttpheader = strhttpheader & "POST /AppUpload.do?ApiName=uploadPhoto HTTP/1.1" & vbCrLf
strhttpheader = strhttpheader & "Referer: upload.photo.163.com" & vbCrLf
strhttpheader = strhttpheader & "Accept: text/*" & vbCrLf
strhttpheader = strhttpheader & "Content-Type: multipart/form-data; boundary=---------------------------7d61194b027e" & vbCrLf
strhttpheader = strhttpheader & "User-Agent: 163UPL~1" & vbCrLf
strhttpheader = strhttpheader & "Host: upload.photo.163.com" & vbCrLf
strhttpheader = strhttpheader & "Cookie: NTES_SESS=fXNzykyeaEePXDtluFzgDZhIAZreEDSvZBDejdd1XrELRfAyoR3AD04hbzaL28FE6gy6R2Jw0uhyy50L9atbMp5pR; _ntes_nvst=1177017267156,|photo|; PSESSIONID=AD876049F3F3404A2BE7F660DAE65E4D.upload-8; NETEASE_SSN=amdlcom; NETEASE_ADV=11&23&1177042318041; ntesAds2781vichy=photo2782logo:97,17200,0,0,0,0,0,0&photo2782duilianb:2,35,0,NaN,0,1,0,0; _ntes_nvid=c15811bbae5405c2dca74a63d1aebd90; _ntes_nnsit=|photo|research|urs|stock|; _ntes_is_survey=photo; MAIL163_SSN=amdlcom; theaddr=%u6E56%u5357; ntesAds2800lancome=photo2800logob:3,15,0,0,0,0,0,0; hitcounter=amdlcom" & vbCrLf & vbCrLf
'strhttpheader = strhttpheader & "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)" & vbCrLf
'strhttpheader = strhttpheader & "Connection: Keep-Alive" & vbCrLf
'strhttpheader = strhttpheader & "Cache-Control: no-cache" & vbCrLf
strbody = strbody & "---------------------------7d61194b027e" & vbCrLf
strbody = strbody & "Content-Disposition:form-data;name=""albumId""" & vbCrLf & vbCrLf
'strbody = strbody & "" & vbCrLf
strbody = strbody & "121357160" & vbCrLf
strbody = strbody & "---------------------------7d61194b027e" & vbCrLf
strbody = strbody & "Content-Disposition:form-data;name=""sid""" & vbCrLf & vbCrLf
' strbody = strbody & "" & vbCrLf
strbody = strbody & "TVRFM056QTBPRFUwTXc9PQ==" & vbCrLf & vbCrLf
strbody = strbody & "---------------------------7d61194b027e" & vbCrLf
strbody = strbody & "Content-Disposition:form-data;name=""OriginDim""" & vbCrLf & vbCrLf
'strbody = strbody & "" & vbCrLf
strbody = strbody & "80;80" & vbCrLf
strbody = strbody & "---------------------------7d61194b027e" & vbCrLf
strbody = strbody & "Content-Disposition: form-data; name=""OriginFile"";filename=""" & Me.Text1 & """" & vbCrLf
'strbody = strbody & "Content-Type: application/octet-stream" & vbCrLf
strbody = strbody & "Content-Type: image/jpeg" & vbCrLf & vbCrLf
'strbody = strbody & "" & vbCrLf
strbody2 = "---------------------------7d61194b027e" & vbCrLf
strbody2 = strbody2 & "Content-Disposition:form-data;name=""SmallerDim""" & vbCrLf & vbCrLf
'strbody2 = strbody2 & "" & vbCrLf
strbody2 = strbody2 & "80;80" & vbCrLf
strbody2 = strbody2 & "---------------------------7d61194b027e" & vbCrLf & vbCrLf
strbody2 = strbody2 & "Content-Disposition: form-data; name=""SmallerFile"";filename=""$$_ORIGIN_$$"" & vbCrLf"
strbody2 = strbody2 & "Content-Type: image/jpeg" & vbCrLf & vbCrLf & vbCrLf
strbody2 = strbody2 & "---------------------------7d61194b027e--" & vbCrLf & vbCrLf
strhttpheader = strhttpheader & "Content-Length: " & CLng(Len(strbody) + Len(strbody2) + FileLen(Me.Text1)) & vbCrLf & vbCrLf
Me.Winsock1.SendData strhttpheader & strbody
DoEvents
Me.Label1 = "Sending file data..."
DoEvents
Dim bytBuff(8191) As Byte
Dim bytRem() As Byte
Open Me.Text1.Text For Binary As #1
times = Int(LOF(1) / 8192)
ReDim bytRem(LOF(1) Mod 8192 - 1)
For i = 1 To times
Get #1, , bytBuff
Me.Winsock1.SendData bytBuff
DoEvents
Next
Get #1, , bytRem
Me.Winsock1.SendData bytRem
DoEvents
Close #1
Me.Winsock1.SendData vbCrLf & strbody2
DoEvents
Me.Label1 = "File was sent successfully."
DoEvents
Me.Winsock1.Close
End Sub
解决方案 »
- 我用程序控制插入一条记录,出现INSERT INTO 语法错误,可是我打开ACCESS,把SQL语句拷贝到ACCESS中执行是没有问题的,请问这是什么原因,谢谢。
- EXCEL读取sql server存储过程结果
- vb水晶报表(crystal report)导致出错的问题
- 高分求解:用皮肤后显示的模态框隐藏,如果解决?
- sql语句中的绝对值函数问题
- vb数组问题
- 各位高手 请帮帮我这个菜鸟!! 谢谢!!
- 请教使用GetClientRect获得的客户区指的是哪个客户区?
- 如何保存、新建文本文件
- access数据库不正常膨胀,很是苦恼,如何压缩,请大家帮忙
- 请高手给出SET ADORS=ADOCON.EXECUTE语句的详细解释!VB+SQL的!
- 我做的支票打印软件 大家多提宝贵意见。
Dim bytRem() As Byte
Open Me.Text1.Text For Binary As #1
times = Int(LOF(1) / 8192)
ReDim bytRem(LOF(1) Mod 8192 - 1)
For i = 1 To times
Get #1, , bytBuff
Me.Winsock1.SendData bytBuff
Me.Winsock1.SendData vbCrLf & strbody2
DoEvents
Next
Get #1, , bytRem
Me.Winsock1.SendData bytRem
Me.Winsock1.SendData vbCrLf & strbody2
DoEvents
Close #1
RichTextBox2.Text = 抓包后的数据(文件的二进制数据之后)Winsock1.SendData RichTextBox2.Text
可是,又是发到了文件二进制数据的一半时就没再发下去了是不是Winsock1不能发大的数据,那要怎么分段来发送呢?高人请帮忙啊~~~