title: VBA post request error - multipart/form-data
body: <p>I am trying to make a POST request on a website in order to upload an Excel file.
  When I do it manually (manually browsing a file in a file input html element) and capture the network traffic, the following message appears on fiddler:</p>
  
  <pre><code>Host: electool.com
  User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0
  Accept: */*
  Accept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
  Accept-Encoding: gzip, deflate, br
  X-Requested-With: XMLHttpRequest
  Content-Type: multipart/form-data; boundary=---------------------------8432274816859
  Content-Length: 35577
  DNT: 1
  Connection: keep-alive
  Referer: https://electool.com/sourcingtool/pageflowViews/tender_view/action.html?pageflow=tender_view:-2
  Cookie: JSESSIONID=87C7F4550EFBDF7A8D6F94C2D021CBB5; electool_sso=5A7A319313EA0EF4
  
  -----------------------------8432274816859
  Content-Disposition: form-data; name="qId"
  
  1
  -----------------------------8432274816859
  Content-Disposition: form-data; name="attachment_1"; filename="A_aFRR negatív_QWERTY00_W38.xlsx"
  Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  ..."
  </code></pre>
  
  <p>I'd like to do the same with excel vba (selecting the file and posting the same message in order to upload the excel file)</p>
  
  <p>The code I have now:</p>
  
  <pre><code>    For i = 1 To ie.Manage.Cookies.Count
       myCookie = myCookie &amp; ie.Manage.Cookies.Item(i).Name &amp; "=" &amp; ie.Manage.Cookies.Item(i).Value &amp; "; "
      Next
      myCookie = Left(myCookie, Len(myCookie) - 2)
      Dim strBoundary As String
      strBoundary = "-----------------------------501911906621"
  
      myURL2 = "https://electool.com/sourcingtool/participant/ajaxSaveAttachment.htm"
      sPayLoad = strBoundary &amp; vbNewLine &amp; _
        "Content-Disposition: form-data; name=""qId""" &amp; vbNewLine &amp; vbNewLine &amp; _
        "1" &amp; vbNewLine &amp; strBoundary &amp; vbNewLine &amp; _
        "Content-Disposition: form-data; name=""attachment_1"";filename=""E_W_37_negativ.xlsx""" &amp; _
        vbNewLine &amp; "Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" &amp; _
        vbNewLine &amp; vbNewLine
  
      sPayLoad = sPayLoad &amp; GetFile(myFile) &amp; strBoundary
  
      With CreateObject("Msxml2.ServerXMLHTTP.6.0")
          .Open "POST", myURL2, False
          .setRequestHeader "Content-Type", "multipart/form-data; boundary=" &amp; strBoundary
          .setRequestHeader "Content-Length", LenB(sPayLoad)
          .setRequestHeader "Host", "electool.com"
          .setRequestHeader "Cookie", myCookie
          .setRequestHeader "Referer", ie.url
          .send (sPayLoad)
          Debug.Print .responseText
      End With
  End Sub
  
  Function GetFile(ByVal FileName As String) As String
      Dim FileContents() As Byte, FileNumber As Integer
      ReDim FileContents(FileLen(FileName) - 1)
      FileNumber = FreeFile()
      Open FileName For Binary As FileNumber
      Get FileNumber, , FileContents
      Close (FileNumber)
      GetFile = StrConv(FileContents, vbUnicode)
  End Function
  </code></pre>
  
  <p>The response I get is this: <code>ng failed; nested exception is com.electool.sourcing.framework.util.request.exception.RequestParameterNotPresentException: Not found parameter: [qId] in request!</code></p>
  
  <p>I also tried what I have found on this link, but still not working (or I am not implementing it well in VBA)
  <a href="https://wqweto.wordpress.com/2011/07/12/vb6-using-wininet-to-post-binary-file/" rel="nofollow noreferrer">https://wqweto.wordpress.com/2011/07/12/vb6-using-wininet-to-post-binary-file/</a></p>