How to send the HTTP multipart/form-data from VB

mscproj used Ask the Experts™
I have a servlet which can accept the follow HTTP Form File operation, and save the file into the server's File System

<FORM METHOD="POST" ACTION="http://localhost:8080/servlet/servletUpload" ENCTYPE="multipart/form-data">
   Select the file to upload  : <INPUT TYPE="FILE" NAME="FILE1" SIZE="25"><BR>

How can I write a VB Client that does the same thing? I got the VB as following, but it doesn't work at all.
I suspect I am sending a string, instead of the file object (sFile).

Any ideas?

Private Sub Command1_Click()
    Dim xmlHttp As New MSXML2.xmlHttp
    'Dim http As New WinHttp.WinHttpRequest
    With CommonDialog1
      .Flags = cdlOFNHideReadOnly Or cdlOFNFileMustExist
      .Filter = "All Files|*.*"
      .FileName = ""
      sFile = .FileName
      sTitle = .FileTitle
    End With
    'MsgBox sFile
   "POST", "http://localhost:8080/servlet/servletUpload", False
    xmlHttp.setRequestHeader "ENCTYPE", "multipart/form-data"
    xmlHttp.send sFile
    If xmlHttp.Status = 200 Then
        MsgBox "Upload Successful!!"
        MsgBox "Upload Unsuccessful!!"
    End If
End Sub

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

hi mscproj,

you have to send the binary data of the file, instead of the file name.

xmlHttp.send <Binary data>

Use Open statement to get the binary data of the file.
Author of the Year 2009

Hi mscproj,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Save as PAQ -- No Refund.

mscproj, Please DO NOT accept THIS comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
DanRollins -- EE database cleanup volunteer
Question placed in PAQ

E-E Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial