ws.SendData at = Timer While Timer - t < 0.2 DoEvents Wend m = FileLen(Orifilename) Dim buffer(4095) As Byte '4k缓冲 times = Int(m / 4096) '循环次数 temp = (m - 4096 * times) - 1 '最后不足4k部分 Dim res() As Byte ReDim res(temp)
Open Orifilename For Binary As #1 For i = 1 To times Step 1 Get #1, , buffer() ws.SendData buffer() t = Timer '延时0.2 While Timer - t < 0.2 DoEvents Wend Next Get #1, , res() ws.SendData res() t = Timer While Timer - t < 0.2 DoEvents Wend Close #1
t = Timer While Timer - t < 0.2 DoEvents WendDoEvents ws.SendData b DoEvents
m = FileLen(Smallfilename) times = Int(m / 4096) temp = (m - 4096 * times) - 1 ReDim res(temp)
Open Smallfilename For Binary As #1 For i = 1 To times Step 1 Get #1, , buffer() ws.SendData buffer() t = Timer While Timer - t < 0.2 DoEvents Wend Next Get #1, , res() ws.SendData res() t = Timer While Timer - t < 0.2 DoEvents Wend Close #1
while timer-t<0.05
doevents
wend
把它加在图片发送之后
如果你还要负责接收,因为TCP/IP是基于流而非基于包的传输协议,你就一定要将每次收到的原始数据缓存到一个先进先出队列里面,当监测出队列中已包含一组完整的数据时再触发上层应用程序处理这组数据,同时注意保存原始数据剩下部分,以便将其拼合到后续接收数据之前。
我自己编写了分包方面的代码,每个包4K
但是网页不认我的数据包
返回bad request
准备按照zhao4zhong1的说法,认真比对原数据和我自己组建的数据
分就给猴哥和zhao4zhong1拉
下面是代码:
ws.RemoteHost = "220.181.31.180"
ws.RemotePort = 80
ws.Connect DoEvents
tmr = Timer
Do Until ws.State = 7
DoEvents
If Timer - tmr >= 10 Then
MsgBox "Connection Timeout. ", vbOKOnly, "Error "
ws.Close
Exit Sub
End If
Loop
'Text2.text = Winsock1.State
strhttpheader = strhttpheader & "POST /dreamatic_altezza/AppInterface/?ApiName=addNewPhoto&username=dreamatic_altezza HTTP/1.1" & vbCrLf
' strhttpheader = strhttpheader & "Accept-Language: zh-cn" & vbCrLf
strhttpheader = strhttpheader & "UA-CPU: x86" & vbCrLf
' strhttpheader = strhttpheader & "Accept-Encoding: gzip, deflate" & vbCrLf
strhttpheader = strhttpheader & "Content-Type: multipart/form-data; boundary=---------------------------7d61194b027e" & vbCrLf
strhttpheader = strhttpheader & "Cache-Control: no-cache" & vbCrLf
strhttpheader = strhttpheader & "Content-Length: " & Str(piclen + txtlen) & vbCrLf
strhttpheader = strhttpheader & "Referer: blog.163.com" & vbCrLf
strhttpheader = strhttpheader & "Accept: text/*" & vbCrLf
strhttpheader = strhttpheader & "User-Agent: UPLOAD~1" & vbCrLf
' strhttpheader = strhttpheader & "Connection: Keep-Alive" & vbCrLf
strhttpheader = strhttpheader & "Host: blog.163.com" & vbCrLf
strhttpheader = strhttpheader & "Cookie:" & cookie & vbCrLf
ws.SendData strhttpheader
DoEvents
ws.SendData at = Timer
While Timer - t < 0.2
DoEvents
Wend
m = FileLen(Orifilename)
Dim buffer(4095) As Byte '4k缓冲
times = Int(m / 4096) '循环次数
temp = (m - 4096 * times) - 1 '最后不足4k部分
Dim res() As Byte
ReDim res(temp)
Open Orifilename For Binary As #1
For i = 1 To times Step 1
Get #1, , buffer()
ws.SendData buffer()
t = Timer '延时0.2
While Timer - t < 0.2
DoEvents
Wend
Next
Get #1, , res()
ws.SendData res()
t = Timer
While Timer - t < 0.2
DoEvents
Wend
Close #1
t = Timer
While Timer - t < 0.2
DoEvents
WendDoEvents
ws.SendData b
DoEvents
m = FileLen(Smallfilename) times = Int(m / 4096)
temp = (m - 4096 * times) - 1 ReDim res(temp)
Open Smallfilename For Binary As #1
For i = 1 To times Step 1
Get #1, , buffer()
ws.SendData buffer()
t = Timer
While Timer - t < 0.2
DoEvents
Wend
Next
Get #1, , res()
ws.SendData res()
t = Timer
While Timer - t < 0.2
DoEvents
Wend
Close #1
t = Timer
While Timer - t < 0.2
DoEvents
Wend
DoEvents
ws.SendData c
DoEventst = Timer
While Timer - t < 0.2
DoEvents
Wend
m = FileLen(Cubefilename) ReDim res(m - 1)
Open Cubefilename For Binary As #1
Get #1, , res()
ws.SendData res() Close #1
t = Timer
While Timer - t < 0.2
DoEvents
WendDoEvents
ws.SendData d
DoEventsDoEvents
ws.SendData e
DoEvents strhttpheader = ""
strhttpheader = strhttpheader & "POST /dreamatic_altezza/AppInterface/?ApiName=uploadEnded&username=dreamatic_altezza HTTP/1.1" & vbCrLf
' strhttpheader = strhttpheader & "Accept-Language: zh-cn" & vbCrLf
strhttpheader = strhttpheader & "UA-CPU: x86" & vbCrLf
' strhttpheader = strhttpheader & "Accept-Encoding: gzip, deflate" & vbCrLf
strhttpheader = strhttpheader & "Content-Type: multipart/form-data; boundary=---------------------------7d61194b027e" & vbCrLf
strhttpheader = strhttpheader & "Cache-Control: no-cache" & vbCrLf
strhttpheader = strhttpheader & "Content-Length: " & Str(txtlenf) & vbCrLf
strhttpheader = strhttpheader & "Referer: blog.163.com" & vbCrLf
strhttpheader = strhttpheader & "Accept: text/*" & vbCrLf
strhttpheader = strhttpheader & "User-Agent: UPLOAD~1" & vbCrLf
'strhttpheader = strhttpheader & "Connection: Keep-Alive" & vbCrLf
strhttpheader = strhttpheader & "Host: blog.163.com" & vbCrLf
strhttpheader = strhttpheader & "Cookie:" & cookie & vbCrLf
ws.SendData strhttpheader
DoEvents
ws.SendData f
请大家注意,我疏忽了
修改方法大家可以根据上面2个文件的发送分包方法修改