传输到服务器上的文件会出错,服务器端提示org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly如果我把传输文件内容替换成文本文件,就没有这个错误了,因此我怀疑是不是我的文件读取程序处需要进行什么处理??这一点我不太明白该怎么做,请赐教。我的程序代码如下
[code]
Dim strHttp As String
Dim strBoundary As String
Dim strBody As String
Dim lngLength As Long
Dim filename as string filename = "d:\abc.zip" ' create a boundary
strBoundary = "----adfasdf2342nasdfasdfasdf"
strBody = strBody & "--" & strBoundary
strBody = strBody & vbCrLf
strBody = strBody & "Content-Disposition: form-data; name=""id"""
strBody = strBody & vbCrLf
strBody = strBody & vbCrLf
strBody = strBody & "0001"
strBody = strBody & vbCrLf
strBody = strBody & "--" & strBoundary & vbCrLf
strBody = strBody & "Content-Disposition: form-data; name=""file""; filename=""" & _
filename & """" & vbCrLf
strBody = strBody & "Content-Type: application/zip" & vbCrLf
strBody = strBody & vbCrLf & getFileData(filename)
strBody = strBody & vbCrLf & "--" & strBoundary & "--" & vbCrLf
lngLength = Len(strBody)
strHttp = "POST /upload.jsp HTTP/1.0" & vbCrLf
strHttp = strHttp & "Host: server" & vbCrLf
strHttp = strHttp & "Content-Type: multipart/form-data; boundary=" & strBoundary & vbCrLf
strHttp = strHttp & "Content-Length: " & lngLength & vbCrLf & vbCrLf
strHttp = strHttp & strBody Winsock1.Protocol = sckTCPProtocol
Winsock1.RemoteHost = "server" Winsock1.RemotePort = 80
Winsock1.SendData strHttpPrivate Function getFileData(ByVal strPath As String)
Dim strReturn As String
Dim bin() As Byte
Dim lngLength As Long
lngLength = FileLen(strPath)
ReDim bin(lngLength - 1)
Open strPath For Binary As #1
Get #1, , bin
StrReturn = bin
getFileData = strReturn
Close #1
End Function
[/code]承蒙赐教,不胜感激。
[code]
Dim strHttp As String
Dim strBoundary As String
Dim strBody As String
Dim lngLength As Long
Dim filename as string filename = "d:\abc.zip" ' create a boundary
strBoundary = "----adfasdf2342nasdfasdfasdf"
strBody = strBody & "--" & strBoundary
strBody = strBody & vbCrLf
strBody = strBody & "Content-Disposition: form-data; name=""id"""
strBody = strBody & vbCrLf
strBody = strBody & vbCrLf
strBody = strBody & "0001"
strBody = strBody & vbCrLf
strBody = strBody & "--" & strBoundary & vbCrLf
strBody = strBody & "Content-Disposition: form-data; name=""file""; filename=""" & _
filename & """" & vbCrLf
strBody = strBody & "Content-Type: application/zip" & vbCrLf
strBody = strBody & vbCrLf & getFileData(filename)
strBody = strBody & vbCrLf & "--" & strBoundary & "--" & vbCrLf
lngLength = Len(strBody)
strHttp = "POST /upload.jsp HTTP/1.0" & vbCrLf
strHttp = strHttp & "Host: server" & vbCrLf
strHttp = strHttp & "Content-Type: multipart/form-data; boundary=" & strBoundary & vbCrLf
strHttp = strHttp & "Content-Length: " & lngLength & vbCrLf & vbCrLf
strHttp = strHttp & strBody Winsock1.Protocol = sckTCPProtocol
Winsock1.RemoteHost = "server" Winsock1.RemotePort = 80
Winsock1.SendData strHttpPrivate Function getFileData(ByVal strPath As String)
Dim strReturn As String
Dim bin() As Byte
Dim lngLength As Long
lngLength = FileLen(strPath)
ReDim bin(lngLength - 1)
Open strPath For Binary As #1
Get #1, , bin
StrReturn = bin
getFileData = strReturn
Close #1
End Function
[/code]承蒙赐教,不胜感激。
strBody = strBody & vbCrLf & getFileData(filename)替换成
strBody = strBody & vbCrLf & "随便写些文字文本"
服务器端接收程序就不会出错,所以我猜测是二进制文件流中有什么字符截断了string,导致没有全部发送到服务器上,但是不知道该怎么做……
http://faq.csdn.net/read/174825.html第一个进来的人,领分结贴。
如果是接分,没来晚:)