VB的winsock实现仿HTTP文件上传解决思路
VB的winsock实现仿HTTP文件上传
大侠帮忙下。我想在网页上实现批量上传文件,但是由于网页浏览器的限制,每次只能浏览选择一个文件,因此想用VB做个ActiveX插件嵌入到网页。由于本人是学C#的,而且也不是接触很久,不是很清楚怎样实现。百度一下了,查找到相关的资料,如下:
Private Sub Command1_Click()
Me.wskUpload.RemoteHost = "127.0.0.1 "
Me.wskUpload.RemotePort = 80
Me.wskUpload.Connect
Me.lblState = "Connecting... "
DoEvents
tmr = Timer
Do Until Me.wskUpload.State = 7
DoEvents
If Timer - tmr > = 10 Then
MsgBox "Connection Timeout. ", vbOKOnly, "Error "
Me.wskUpload.Close
Exit Sub
End If
Loop
Me.lblState = "Ready to send... "
strhttpheader = strhttpheader & "POST /WebApplication3/Upload.aspx HTTP/1.1 " & vbCrLf
strhttpheader = strhttpheader & "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, */* " & vbCrLf
strhttpheader = strhttpheader & "Referer: http://localhost/WebApplication3/Upload.aspx " & vbCrLf
strhttpheader = strhttpheader & "Accept-Language:zh-cn " & vbCrLf
strhttpheader = strhttpheader & "Content-Type: multipart/form-data; boundary=-----------------------------7d724224204ae " & vbCrLf
大侠帮忙下。我想在网页上实现批量上传文件,但是由于网页浏览器的限制,每次只能浏览选择一个文件,因此想用VB做个ActiveX插件嵌入到网页。由于本人是学C#的,而且也不是接触很久,不是很清楚怎样实现。百度一下了,查找到相关的资料,如下:
Private Sub Command1_Click()
Me.wskUpload.RemoteHost = "127.0.0.1 "
Me.wskUpload.RemotePort = 80
Me.wskUpload.Connect
Me.lblState = "Connecting... "
DoEvents
tmr = Timer
Do Until Me.wskUpload.State = 7
DoEvents
If Timer - tmr > = 10 Then
MsgBox "Connection Timeout. ", vbOKOnly, "Error "
Me.wskUpload.Close
Exit Sub
End If
Loop
Me.lblState = "Ready to send... "
strhttpheader = strhttpheader & "POST /WebApplication3/Upload.aspx HTTP/1.1 " & vbCrLf
strhttpheader = strhttpheader & "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, */* " & vbCrLf
strhttpheader = strhttpheader & "Referer: http://localhost/WebApplication3/Upload.aspx " & vbCrLf
strhttpheader = strhttpheader & "Accept-Language:zh-cn " & vbCrLf
strhttpheader = strhttpheader & "Content-Type: multipart/form-data; boundary=-----------------------------7d724224204ae " & vbCrLf