Reputation: 31463
I have an Excel VBA macro which does the equivalent of the following HTTP POST which works successfully:
Set WebClient = CreateObject("WinHttp.WinHttpRequest.5.1")
' ... Configure WebClient for a POST request
RequestBody = "<request>"
WebClient.send RequestBody
Previously, I had explicitly set the type of RequestBody as a String as in the following:
Set WebClient = CreateObject("WinHttp.WinHttpRequest.5.1")
' ... Configure WebClient for a POST request
Dim RequestBody As String
RequestBody = "<request>"
WebClient.send RequestBody
This appeared to work correctly except that the server received no request content.
On debugging through both versions a watch on RequestBody described its type as 'Variant/String' and the content was correct.
Why does the addition of a type cause this issue?
Upvotes: 1
Views: 1125
Reputation: 78175
Hmm...
Try to add the reference to WinHTTP library (Tools - References). For no obvious reason sometimes it matters.
But Send method is declared as using a Variant parameter anyway, so making it String doesn't make sense.
Upvotes: 3