我模仿某篇文章如下vb代码,它是一个用socket来在web上传文件的控件,一点按钮就会从
text里面读取文件,然后用socket封装成http协议的数据发送到web服务器。我现在的问题
是如何得让发过去的数据和当前页面保持同一个session,如果在我这个特例中(domino服务器)
只要设置http头种的Cookie为DomAuthSessId=7F26AF2EBAFE7CEABB06D131D83467FB",但是这个
DomAuthSessId又是如何得到呢?有什么办法是对任何web服务器都可以与当前页面保持session
一致?还有就是在web中上传文件用socket好吗,用vb的inet控件如何?因为用<FILE标签
上传文件比较多限制,一次只能选一个文件,所以
Private Sub Command1_Click()
Me.Winsock1.RemoteHost = "127.0.0.1"
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 /fmUpLoadFile?OpenForm&Seq=1 HTTP/1.1" & vbCrLf
strhttpheader = strhttpheader & "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*" & vbCrLf
strhttpheader = strhttpheader & "Referer: http://127.0.0.1/fmUpLoadFile?OpenForm" & vbCrLf
strhttpheader = strhttpheader & "Accept-Language: zh-cn" & vbCrLf
strhttpheader = strhttpheader & "Content-Type: multipart/form-data; boundary=---------------------------7d43b92a4302a2" & vbCrLf
strhttpheader = strhttpheader & "Accept-Encoding: gzip, deflate" & vbCrLf
strhttpheader = strhttpheader & "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" & vbCrLf
strhttpheader = strhttpheader & "Host: 10.123.78.56" & vbCrLf
strhttpheader = strhttpheader & "Connection: Keep-Alive" & vbCrLf
strhttpheader = strhttpheader & "Cache-Control: no-cache" & vbCrLf
'strhttpheader = strhttpheader & "Cookie: DomAuthSessId=7F26AF2EBAFE7CEABB06D131D83467FB" & vbCrLf
strbody = strbody & "-----------------------------7d43b92a4302a2" & vbCrLf
strbody = strbody & "Content-Disposition: form-data; name=""__Click""" & vbCrLf
strbody = strbody & "" & vbCrLf
strbody = strbody & "3a5b4ec1275d80cf48256f350010c470/$Body/0.2B2" & vbCrLf
strbody = strbody & "-----------------------------7d43b92a4302a2" & vbCrLf
strbody = strbody & "Content-Disposition: form-data; name=""fdFolder""" & vbCrLf
strbody = strbody & "" & vbCrLf
strbody = strbody & "ea7aee50e949df4f48256f38002a8377" & vbCrLf
strbody = strbody & "-----------------------------7d43b92a4302a2" & vbCrLf
strbody = strbody & "Content-Disposition: form-data; name=""%%File3a5b4ec1275d80cf48256f350010c470.$Body.0.230""; filename=""" + Me.Text1.Text + """" & vbCrLf
strbody = strbody & "Content-Type: text/plain" & vbCrLf
strbody = strbody & "" & vbCrLf
strbody2 = vbCrLf & "-----------------------------7d43b92a4302a2--" & vbCrLf
strhttpheader = strhttpheader & "Content-Length: " & CLng(Len(strbody) + Len(strbody2) + FileLen(Me.Text1.Text)) & vbCrLf
strhttpheader = strhttpheader & "" & vbCrLf
Me.Winsock1.SendData strhttpheader
DoEvents Me.Winsock1.SendData 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 strbody2
DoEvents
Me.Label1 = "File was sent successfully."
DoEvents
Me.Winsock1.Close
End Sub
text里面读取文件,然后用socket封装成http协议的数据发送到web服务器。我现在的问题
是如何得让发过去的数据和当前页面保持同一个session,如果在我这个特例中(domino服务器)
只要设置http头种的Cookie为DomAuthSessId=7F26AF2EBAFE7CEABB06D131D83467FB",但是这个
DomAuthSessId又是如何得到呢?有什么办法是对任何web服务器都可以与当前页面保持session
一致?还有就是在web中上传文件用socket好吗,用vb的inet控件如何?因为用<FILE标签
上传文件比较多限制,一次只能选一个文件,所以
Private Sub Command1_Click()
Me.Winsock1.RemoteHost = "127.0.0.1"
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 /fmUpLoadFile?OpenForm&Seq=1 HTTP/1.1" & vbCrLf
strhttpheader = strhttpheader & "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*" & vbCrLf
strhttpheader = strhttpheader & "Referer: http://127.0.0.1/fmUpLoadFile?OpenForm" & vbCrLf
strhttpheader = strhttpheader & "Accept-Language: zh-cn" & vbCrLf
strhttpheader = strhttpheader & "Content-Type: multipart/form-data; boundary=---------------------------7d43b92a4302a2" & vbCrLf
strhttpheader = strhttpheader & "Accept-Encoding: gzip, deflate" & vbCrLf
strhttpheader = strhttpheader & "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" & vbCrLf
strhttpheader = strhttpheader & "Host: 10.123.78.56" & vbCrLf
strhttpheader = strhttpheader & "Connection: Keep-Alive" & vbCrLf
strhttpheader = strhttpheader & "Cache-Control: no-cache" & vbCrLf
'strhttpheader = strhttpheader & "Cookie: DomAuthSessId=7F26AF2EBAFE7CEABB06D131D83467FB" & vbCrLf
strbody = strbody & "-----------------------------7d43b92a4302a2" & vbCrLf
strbody = strbody & "Content-Disposition: form-data; name=""__Click""" & vbCrLf
strbody = strbody & "" & vbCrLf
strbody = strbody & "3a5b4ec1275d80cf48256f350010c470/$Body/0.2B2" & vbCrLf
strbody = strbody & "-----------------------------7d43b92a4302a2" & vbCrLf
strbody = strbody & "Content-Disposition: form-data; name=""fdFolder""" & vbCrLf
strbody = strbody & "" & vbCrLf
strbody = strbody & "ea7aee50e949df4f48256f38002a8377" & vbCrLf
strbody = strbody & "-----------------------------7d43b92a4302a2" & vbCrLf
strbody = strbody & "Content-Disposition: form-data; name=""%%File3a5b4ec1275d80cf48256f350010c470.$Body.0.230""; filename=""" + Me.Text1.Text + """" & vbCrLf
strbody = strbody & "Content-Type: text/plain" & vbCrLf
strbody = strbody & "" & vbCrLf
strbody2 = vbCrLf & "-----------------------------7d43b92a4302a2--" & vbCrLf
strhttpheader = strhttpheader & "Content-Length: " & CLng(Len(strbody) + Len(strbody2) + FileLen(Me.Text1.Text)) & vbCrLf
strhttpheader = strhttpheader & "" & vbCrLf
Me.Winsock1.SendData strhttpheader
DoEvents Me.Winsock1.SendData 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 strbody2
DoEvents
Me.Label1 = "File was sent successfully."
DoEvents
Me.Winsock1.Close
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货