Vb6 HTTP post request on Windows XP

I have a problem sending a POST request from VB6. The code below works correctly on Windows7, but on Windows XP it runs without any runtime error and sends the batch, but it doesn't seem to add the message data to the batch. My code looks 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 line "bar = foo & foo = bar"

I've already tried to add links to Microsoft XML, v4.0.

+3


source to share


3 answers


I found a solution. I changed the code like this:

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 a link to "Microsoft WinHTTP Services, version 5.1"

And now it works.

+2


source


Just guess here, but try changing this line by adding 10 (or 100) to the length. change this xmlhttp.setRequestHeader "Content-Length", Len (options) to this xmlhttp.setRequestHeader "Content-Length", Len (options) + 10



I was never told why I should do this, just to add 10 or more lengths.

0


source


Have you tried putting parentheses around the send parameter 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)

      

What I think is happening because since you are sending the ByRef parameter, the ServerXMLHTTP object gets confused when choosing the correct overload of the submit method. It thinks that you are sending a pointer to an IStream when in fact you are trying to send a BSTR. By putting the parameter in parentheses, it forces the compiler to send the ByVal variable instead of ByRef, and thus the compiler understands that you are not sending a pointer and are choosing the correct overload of the send function.

0


source







All Articles