VB代码如下:提交后转向zxb这个servlet,在jbuilder中加断点调试时
发现,request.getInputStream();得到一个空的流.......请问怎么回事????????????????????????Private Sub Command1_Click()
Dim strLogin As String
Dim iSendLength As Integer
Dim strSendHeader As StringstrLogin = "http://localhost:8080/zxb"
Dim lngL As Long, bytFile() As Byte
Open "C:\new.doc" For Binary Access Read Write Shared As #1
lngL = LOF(1)
ReDim bytFile(lngL - 1)
Get #1, , bytFile
Close #1 strSendHeader = strSendHeader & "Content-Type:multipart/form-data" & vbCrLf strSendHeader = strSendHeader & "Content-Length: " & lngL - 1 & vbCrLf Inet1.Execute strLogin, "POST", bytFile, strSendHeader
End Sub
发现,request.getInputStream();得到一个空的流.......请问怎么回事????????????????????????Private Sub Command1_Click()
Dim strLogin As String
Dim iSendLength As Integer
Dim strSendHeader As StringstrLogin = "http://localhost:8080/zxb"
Dim lngL As Long, bytFile() As Byte
Open "C:\new.doc" For Binary Access Read Write Shared As #1
lngL = LOF(1)
ReDim bytFile(lngL - 1)
Get #1, , bytFile
Close #1 strSendHeader = strSendHeader & "Content-Type:multipart/form-data" & vbCrLf strSendHeader = strSendHeader & "Content-Length: " & lngL - 1 & vbCrLf Inet1.Execute strLogin, "POST", bytFile, strSendHeader
End Sub
顺便问一下,如何在一个表中选择某几个字段的值是最大,并把这几个最大值显示在TEXT控件中呢?
如果不用MIME编码,那岂不是要所有文件数据一个接一个,那sevrlet怎样知道数据哪里到哪里是一个文件,哪里到哪里是另一个文件.虽说这个例子只是发一个文件,但,码还是要编的!
strSendHeader = strSendHeader & "multipart/form-data; boundary=-------BY_GARFIELD
" & vbCrLf
strSendHeader = strSendHeader & "Content-Length: " & lngL - 1 & vbCrLf
strSendBody = strSendBody & "-------BY_GARFIELD" & vbcrlf
strSendBody = strSendBody & "Content-Disposition: form-data; name=""file1""; filename=""""" & vbcrlf
strSendBody = strSendBody & "Content-Type: application/octet-stream" & vbcrlf
strSendBody = strSendBody & bytFileInet1.Execute strLogin, "POST", strSendBody, strSendHeader
还有就是base64编码是不是应该看服务器端啊,WEB端要求base64编码才去编码?
Boundary 说明了分界符是 "-------BY_GARFIELD"
这样才能区分所谓的 multipart(多部分),究竟是怎样 part(分部)。你刚才声明了Content-Type:multipart/form-data,据个例说相当于对服务器说“我要给你几份文件”,但是你没有说明每份文件有多少页,服务器只能当一份文件来看。然而这样的请求在实际中是错误的。
而加了 Boundary, 就等于说明了 “这份文件到这里开始(结束)”
base64编码看客户端的。我刚才发的:
Content-Type: application/octet-stream客户端声明正文类型,编码是二进制数据流(octet-stream),就不需要用base64编码。
对了,我忘了一些东西,改一改body部分strSendBody = strSendBody & "-------BY_GARFIELD" & vbcrlf
strSendBody = strSendBody & "Content-Disposition: form-data; name=""file1""; filename=""""" & vbcrlf
strSendBody = strSendBody & "Content-Type: application/octet-stream" & vbcrlf & vbcrlf
strSendBody = strSendBody & bytFile
strSendBody = strSendBody & vbcrlf "-------BY_GARFIELD--" & vbcrlf & vbcrlfbtw: entice(踏雪寻梅) 和 xfreedom(xfreedom) 是同一个人?
Content-Disposition: form-data; name="text1"Text test
-----------------------------5fi25134734389--
Content-Disposition: form-data;
name="file1"; filename="E:\GIF\girl.gif"
Content-Type: image/gifGIF89a? ????噜鄛}}^^^υ,?-----------------------------------这部分是怎么发送的?
-----------------------------5fi25134734389? ????噜鄛}}^^^υ,?-----------------------------------这部分是怎么发送的?
其它是串,可以用&简单的相连吗>?不行的我转码试试....
Dim strLogin As String
Dim iSendLength As Integer
Dim strSendHeader As String
Dim strSendBody As StringstrLogin = "http://localhost/zxb.asp"
Dim lngL As Long, bytFile() As Byte
Open "C:\new.doc" For Binary Access Read Write Shared As #1
lngL = LOF(1)
ReDim bytFile(lngL - 1)
Get #1, , bytFile
Close #1strSendHeader = strSendHeader & "multipart/form-data; boundary=-------BY_GARFIELD" & vbCrLf
strSendHeader = strSendHeader & "Content-Length: " & lngL - 1 & vbCrLf
strSendBody = strSendBody & "-------BY_GARFIELD" & vbcrlf
strSendBody = strSendBody & "Content-Disposition: form-data; name=""file1""; filename=""""" & vbcrlf
strSendBody = strSendBody & "Content-Type: application/octet-stream" & vbcrlf & vbcrlf
strSendBody = strSendBody & bytFile
strSendBody = strSendBody & "-------BY_GARFIELD--" & vbcrlf & vbcrlf Inet1.Execute strLogin, "POST", strSendBody, strSendHeader
End Sub编译时提示strSendBody = strSendBody & bytFile处类型不匹配
用Winsock分开几次发送。
Dim iSendLength As Integer
Dim strSendHeader As String
Dim strSendBody As String
Dim stepcount As Integer
Dim strSendBody1() As Byte
Dim strSendBody2 As String
Private Sub Command1_Click()
Winsock1.RemoteHost = "218.0.188.159" '设置连接的网址
Winsock1.RemotePort = 80 '设置要连接的远程端口号
Winsock1.Connect '返回与远程计算机的连接。
End Sub
Private Sub Winsock1_Connect()
On Error Resume Next
Winsock1.senddata strSendHeader
DoEvents
Winsock1.senddata strSendBody
DoEvents
Winsock1.senddata strSendBody1
DoEvents
Winsock1.senddata strSendBody2
End SubPrivate Sub Form_Load()
strLogin = "zxb.asp"Dim lngL As Long, bytFile() As Byte
Open "C:\new.doc" For Binary Access Read Write Shared As #1
lngL = LOF(1)
ReDim bytFile(lngL - 1)
Get #1, , bytFile
Close #1strSendHeader = " POST /" & strLogin & " HTTP/1.1" & vbCrLf
strSendHeader = strSendHeader & "Accept: application/vnd.ms-excel, application/msword, */*" & vbCrLf
strSendHeader = strSendHeader & "Accept-Language: zh-cn" & vbCrLf
strSendHeader = strSendHeader & "multipart/form-data; boundary=-------BY_GARFIELD" & vbCrLf
strSendHeader = strSendHeader & "Content-Length: " & lngL - 1 & vbCrLf
strSendBody = strSendBody & "-------BY_GARFIELD" & vbCrLf
strSendBody = strSendBody & "Content-Disposition: form-data; name=""file1""; filename=""""" & vbCrLf
strSendBody = strSendBody & "Content-Type: application/octet-stream" & vbCrLf & vbCrLf
strSendBody1 = bytFile
strSendBody2 = "-------BY_GARFIELD--" & vbCrLf & vbCrLfEnd Sub
没有成功帮我看看错在那里?
strSendHeader = "Host: 127.0.0.1" & vbCrLf
strSendHeader = "User-agent: garfield" & vbCrLf
……
strSendHeader = strSendHeader & "Content-Length: " & lngL - 1 & vbCrLf & vbCrLfstrSendBody = strSendBody & "-------BY_GARFIELD" & vbCrLf
4。在java程序中用ServletInputStream servletInputStream=request.getInputStream()获得输入流5。转化为字节数组6。用base64解码7。写入文件或者数据库 完毕
在哪里人没有看到啊