3

How to send POST request to remote URL using VB6 ?

user229044
  • 232,980
  • 40
  • 330
  • 338
KJW
  • 15,035
  • 47
  • 137
  • 243

3 Answers3

5

We can do this way also

Set myMSXML = CreateObject("Microsoft.XmlHttp")
myMSXML.open "POST", "http://....", False
myMSXML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
myMSXML.setRequestHeader "User-Agent", "Firefox 3.6.4"
myMSXML.send "param1=value2&param2=value2"
MsgBox myMSXML.responseText

More references you can check http://smartreferences.blogspot.in

Palanikumar
  • 6,940
  • 4
  • 40
  • 51
5

Many ways to approach this. You can use WinInet API, WinHTTP API, WinHTTPRequest, or XMLHTTPRequest. I prefer the lower leveled Winsock, and you can read about it here: http://www.vbforums.com/showthread.php?t=334645 . Winsock is a bit more complicated, and but a bit more powerful, in my opinion. If you want to do it simple and sweet, XML HTTP Request is the way to go, I use it in javascript too. Try something like:

Set myMSXML = New MSXML.XMLHTTPRequest
myMSXML.open "POST", URL, True
myMSXML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
myMSXML.setRequestHeader "User-Agent", "Firefox 3.6.4"
myMSXML.OnReadyStateChange = (Shown below)
myMSXML.send YourPostDataString

And the OnReadyStateChange function:

Dim HttpResponse As String

HttpResponse = myMSXML.responseText

If you find my code not working, or you're a bit confused, I'm sorry, I'm a bit rusty with VB nowadays. You can check out the official Microsoft documentation on XMLHTTPRequest here: http://msdn.microsoft.com/en-us/library/ms759148%28VS.85%29.aspx

LostInTheCode
  • 1,724
  • 2
  • 15
  • 22
  • +1 Similar to the code posted in [this question](http://stackoverflow.com/questions/749491/soap-post-failure) which is a good sign. – MarkJ Nov 03 '10 at 11:57
1

For my API worked only with "application/json" in "Content-Type" header. Here is my code:

textJSON = "{ ""field1"":""value1"", ""field2"":""value2""}"
Set myMSXML = CreateObject("Microsoft.XmlHttp")
myMSXML.Open "POST", "http://...", False
myMSXML.setRequestHeader "Content-Type", "application/json"
myMSXML.setRequestHeader "User-Agent", "Firefox 3.6.4"
myMSXML.send textJSON
MsgBox myMSXML.responseText