Hi,

I have tried to write a method to upload a file via HTTP Post in VBA. Unfortunately, the code does not work and I could not find why. Here is the snippet:

[VBA]Function WinHTTPPostRequest(Url, FormData, Boundary) As String
Dim http
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
http.Open "POST", Url, False
http.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & Boundary
http.setRequestHeader "Content-Length", Len(FormData)
http.send FormData
WinHTTPPostRequest = http.ResponseText
End Function[/VBA]

Boundary value is the following:
c0KGlCJxuG9d3JCYZ4D1J6Gw8OiOxv6d

FormData value is the following:
--c0KGlCJxuG9d3JCYZ4D1J6Gw8OiOxv6d
Content-Disposition: form-data; name="data[automation]"

excel.vba
--c0KGlCJxuG9d3JCYZ4D1J6Gw8OiOxv6d
Content-Disposition: form-data; name="data[filename]"; filename="import.csv"
Content-Type: text/csv

id,month1,month2,month3,month4,month5,month6,month7,month8,month9,month10,m onth11,month12
1915,0,0,0,0,0,0,0,0,0,0,0,1250
1201,0,0,0,0,0,0,0,0,0,0,0,2400
--c0KGlCJxuG9d3JCYZ4D1J6Gw8OiOxv6d--


Based on network monitor tool, all the data is sent to the server as expected.

However, the data[automation], nor the data[filename] parameters are recognized by the server script. I see only headers on the server side - Content-Type and Content-Length.

[Content-Type] => multipart/form-data; boundary=c0KGlCJxuG9d3JCYZ4D1J6Gw8OiOxv6d; Charset=UTF-8
[Content-Length] => 437


What's wrong in the VBA code or in the sent data? Thank's for your tips.