Reputation: 15251
How to send POST request to remote URL using VB6 ?
Upvotes: 3
Views: 28789
Reputation: 11
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
Upvotes: 1
Reputation: 7150
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¶m2=value2"
MsgBox myMSXML.responseText
More references you can check http://smartreferences.blogspot.in
Upvotes: 5
Reputation: 1744
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
Upvotes: 5