Vb6 http post request on windows XP

aberti picture aberti · Mar 30, 2012 · Viewed 8.4k times · Source

I have a problem sending POST request with VB6. The code below works properly on Windows7 but on Windows XP it run without any runtime error and it sends the packet but looks like it doesn't append the post data in the packet. My code is like this:

Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "POST", url, False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.setRequestHeader "Content-Length", Len(parameters)
xmlhttp.Send parameters

where paramaters contains the string "bar=foo&foo=bar"

I already tried to add the references to Microsoft XML, v4.0.

Answer

aberti picture aberti · Apr 3, 2012

I found a solution. I changed the code in this way:

Dim xmlhttp As WinHttp.WinHttpRequest 
...

Set xmlhttp = New WinHttp.WinHttpRequest

xmlhttp.open "POST", url, False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.setRequestHeader "Content-Length", Len(parameters)
xmlhttp.Send parameters

Adding the reference to "Microsoft WinHTTP Services, version 5.1"

And now it works.