title: send a file and parameter HTTP Post with VBS
body: <p>I'm new working with HTTP protocol and haven't worked with VBS for some time.
  The problem I'm having is sending a parameter and an upload file to a web service.
  I just don't understand what some of the code is. Below is part of the code.</p>
  
  <pre><code>     With CreateObject("MSXML2.ServerXMLHTTP") 
      .setOption 2, 13056 'http://msdn.microsoft.com/en- 
       us/library/ms763811(v=VS.85).aspx  
      .SetTimeouts 0, 60000, 300000, 300000
      .Open "POST", 
      "https://192.168.100.100/api/import_file_here.json", False 
      .SetRequestHeader "Content-type", "multipart/form-data; boundary=" &amp; 
      strBoundary  'THIS SEND THE FILE   
      .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"  ' 
       THIS SEND THE PARAMETER.
      .Send bytPD ' sends param
      .Send bytPayLoad   '''SEND FILE
  </code></pre>
  
  <p>I know I can't use .Send twice.  I believe I need to make a change in the below code block.</p>
  
  <pre><code> With CreateObject("ADODB.Stream")
  .Mode = 3
  .Charset = "Windows-1252"
  .Open
  .Type = 2
  .WriteText "--" &amp; strBoundary &amp; vbCrLf
  '.WriteText "Content-Disposition: form-data; name=""file"";  filename=""" &amp; 
    strFile &amp; """" &amp; vbCrLf
   .WriteText "Content-Disposition: form-data; name=""file""; 
    publication=""moveit_test_pub"""
  '.WriteText "Content-Type: """ &amp; strContentType &amp; """" &amp; vbCrLf &amp; vbCrLf
  .Position = 0
  .Type = 1
  .Write bytData
  .Position = 0
  .Type = 2
  .Position = .Size
  .WriteText vbCrLf &amp; "--" &amp; strBoundary &amp; "--"
  .Position = 0
  .Type = 1
   bytPayLoad = .Read
   bytPD = "publication=moveit_test_pub"
  </code></pre>
  
  <p>bytPD = "publication=moveit_test_pub" is the parameter I need along with the file upload.  I'm just not sure how to add it to the above block.  If that's where I'm supposed to change.  I'm posting the entire code below for reference.
  Thanks for all your help!</p>
  
  <pre><code>strFilePath = "C:\SCAudience_TEST5.txt"
  UploadFile strFilePath, strUplStatus, strUplResponse
      MsgBox strUplStatus &amp; vbCrLf &amp; strUplResponse
  
      Sub UploadFile(strPath, strStatus, strResponse)
  
      Dim strFile, strExt, strContentType, strBoundary, bytPD, bytData, 
      bytPayLoad
  
      On Error Resume Next
      With CreateObject("Scripting.FileSystemObject")
          If .FileExists(strPath) Then
              strFile = .GetFileName(strPath)
              strExt = .GetExtensionName(strPath)
          Else
              strStatus = "File not found"
              Exit Sub
          End IF
      End With
      With CreateObject("Scripting.Dictionary")
          .Add "txt", "text/plain"
          .Add "html", "text/html"
          .Add "php", "application/x-php"
          .Add "js", "application/x-javascript"
          .Add "vbs", "application/x-vbs"
          .Add "bat", "application/x-bat"
          .Add "jpeg", "image/jpeg"
          .Add "jpg", "image/jpeg"
          .Add "png", "image/png"
          .Add "exe", "application/exe"
          .Add "doc", "application/msword"
          .Add "docx", "application/vnd.openxmlformats- 
           officedocument.wordprocessingml.document"
          .Add "xls", "application/vnd.ms-excel"
          .Add "xlsx", "application/vnd.openxmlformats- 
           officedocument.spreadsheetml.sheet"
          strContentType = .Item(LCase(strExt))
      End With
      If strContentType = "" Then
          strStatus = "Invalid file type"
          Exit Sub
      End If
      With CreateObject("ADODB.Stream")
          .Type = 1
          .Mode = 3
          .Open
          .LoadFromFile strPath
          If Err.Number &lt;&gt; 0 Then
              strStatus = Err.Description &amp; " (" &amp; Err.Number &amp; ")"
              Exit Sub
          End If
         bytData = .Read
           bytPD = "publication=moveit_test_pub"
      End With
      strBoundary = String(6, "-") &amp; Replace(Mid(CreateObject("Scriptlet.TypeLib").Guid, 2, 36), "-", "")
      With CreateObject("ADODB.Stream")
          .Mode = 3
          .Charset = "Windows-1252"
          .Open
          .Type = 2
          .WriteText "--" &amp; strBoundary &amp; vbCrLf
         ' .WriteText "Content-Disposition: form-data; name=""file"";  filename=""" &amp; strFile &amp; """" &amp; vbCrLf
        .WriteText "Content-Disposition: form-data; name=""file""; publication=""moveit_test_pub"""
          '.WriteText "Content-Type: """ &amp; strContentType &amp; """" &amp; vbCrLf &amp; vbCrLf
          .Position = 0
          .Type = 1
         .Write bytData
          .Position = 0
          .Type = 2
          .Position = .Size
       ''   .WriteText vbCrLf &amp; "--" &amp; strBoundary &amp; "--"
          .Position = 0
          .Type = 1
         bytPayLoad = .Read
           bytPD = "publication=moveit_test_pub"
      End With
      With CreateObject("MSXML2.ServerXMLHTTP") 
          .setOption 2, 13056 'http://msdn.microsoft.com/en-us/library/ms763811(v=VS.85).aspx 
          .SetTimeouts 0, 60000, 300000, 300000
          .Open "POST", "https://192.168.100.100/api/import_file_here.json", False 
          .SetRequestHeader "Content-type", "multipart/form-data; boundary=" &amp; strBoundary  'THIS SEND THE FILE  IF BOTH SELECTED SEND PARM AND TEXT OF FILE
  
          .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"  ' THIS SEND THE PARAMETER.
     ''' .Send bytPD ' sends param
        '  .SetRequestHeader "Content-type", "multipart/form-data; boundary=" &amp; strBoundary 'NEW LINE
         .Send bytPayLoad   '''SEND FILE
  
           MsgBox bytPD
          If Err.Number &lt;&gt; 0 Then
              strStatus = Err.Description &amp; " (" &amp; Err.Number &amp; ")"
          Else
              strStatus = .StatusText &amp; " (" &amp; .Status &amp; ")"
          End If
          If .Status = "400" Then strResponse = .ResponseText
  
         If   .Status = "401" Then strResponse = .ResponseText
  
        If    .Status = "200" Then strResponse = .ResponseText    
  
      End With
  
  
  End Sub
  </code></pre>