tags:

views:

457

answers:

1

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?

+1  A: 

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.

GSerg
I'd expect it to throw some kind of error at runtime if it is passed a string, but instead it just sends nothing.
Matthew Murdoch