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

解决方案 »

  1.   

    serlvet代码肯定是正确的,用html的post上传文件正常.....
      

  2.   

    这个功能我做过,等我查一下告诉你吧,OK?
    顺便问一下,如何在一个表中选择某几个字段的值是最大,并把这几个最大值显示在TEXT控件中呢?
      

  3.   

    你忘了用Base64格式编码Mime格式发送
      

  4.   

    具体就是要编码.就着样二进制发过去肯定是不行的.况且html上传的也有上传几个文件那种.
    如果不用MIME编码,那岂不是要所有文件数据一个接一个,那sevrlet怎样知道数据哪里到哪里是一个文件,哪里到哪里是另一个文件.虽说这个例子只是发一个文件,但,码还是要编的!
      

  5.   


    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
       
      

  6.   

    问题还是没解决啊,文件怎么样以Mime格式发送发送?这才是根本问题啊!
    还有就是base64编码是不是应该看服务器端啊,WEB端要求base64编码才去编码?
      

  7.   

    你说的MIME和上面代码里的Content-Type:multipart/form-data有什么区别?
      

  8.   

    multipart/form-data; boundary=-------BY_GARFIELD
    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) 是同一个人?
      

  9.   

        -----------------------------5fi25134734389
    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? ????噜鄛}}^^^υ,?-----------------------------------这部分是怎么发送的?
      

  10.   

    我的QQ是4886611能和Garfield(猫仔)或entice(踏雪寻梅) 交流一下么?
      

  11.   

    Garfield(猫仔) 能把你的QQ号告诉我么?
      

  12.   

    bytFile是流
    其它是串,可以用&简单的相连吗>?不行的我转码试试....
      

  13.   

    liuruhong(蓝色街灯) 用你给的XMLHTTP上传成功了,但是必须在服务器和客户端都安装MS XML DOM 3.0 和MDAC 2.5 。你有没有用直接使用WINSOCKE或Inet1直接模仿FORM上传数据的方法?
      

  14.   

    Private Sub Command1_Click()
    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处类型不匹配
      

  15.   

    strSendBody = strSendBody & bytFile是啊,一个是字串,一个是byte流,不能这样相加的...我上面也说过了...不行的.
      

  16.   

    如果不需要一定是Inet,试一下用Winsock。
    用Winsock分开几次发送。
      

  17.   

    Dim strLogin As String
    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
    没有成功帮我看看错在那里?
      

  18.   

    strSendHeader = "POST /" & strLogin & " HTTP/1.1" & vbCrLf
    strSendHeader = "Host: 127.0.0.1" & vbCrLf
    strSendHeader = "User-agent: garfield" & vbCrLf
    ……
    strSendHeader = strSendHeader & "Content-Length: " & lngL - 1 & vbCrLf & vbCrLfstrSendBody = strSendBody & "-------BY_GARFIELD" & vbCrLf
      

  19.   

    有没有人做过可以用的东西啊,我现在有的东西是客户端经过byte64编码,然后传到服务器,再在servlet中进行byte64解码,然后写到相应文件中,可是服务器中收到的字符串要比客户端上传前多2。客户端加密以后上传的语句是    InternetConnection.Execute strHttpURL, "POST", strFormData & vbCrLf, "Content-Type:application/x-www-form-urlencoded"  服务器端就是servlet里面String InfoTitle = request.getParameter("TestData");得到数据,然后进行一些加工写到文件中。对于txt文件成功,但是在服务器的文件的最后有两个空格,别的二进制文件则不能打开,图片则根本不是原来的样子,郁闷
     
      

  20.   

    我的IIS出问题了,笔记本上面没装VB,所以测试不了。
      

  21.   

    已经结束了,解决了,测试过了40M的word文档,大概用时20s还有txt,rm avi 等文件,都可以很好的上传到服务器,方法是:1。读取文件2。base64加密3。完成发送命令的配置    InternetConnection.Execute strHttpURL, "Post", bb, "Content-Type: application/octet-stream"   strHttpURL为服务器地址,是接收文件的servlet的地址“post”表示传送方法 bb为加密过的传送内容,第四个参数表示上传的是二进制数据
    4。在java程序中用ServletInputStream servletInputStream=request.getInputStream()获得输入流5。转化为字节数组6。用base64解码7。写入文件或者数据库  完毕
      

  22.   

    我的代码是不是还缺少base64加密,谁能告诉我用base64加密的代码?
      

  23.   

    duye(Kill_CSS) 不知道你是么base64加密的,还有如果POST的不光是文件,还有几个字符串,应该怎么做?
      

  24.   

    entice(踏雪寻梅) , 今天我写给 xfreedom的代码看过了么?
      

  25.   

    Garfield(猫仔|正在学VC++.NET
    在哪里人没有看到啊
      

  26.   

    http://expert.csdn.net/Expert/topic/2079/2079536.xml?temp=.1568109
      

  27.   

    Garfield(猫仔|正在学VC++.NET) (到http://expert.csdn.net/Expert/topic/1856/1856531.xml?temp=.697796去接分