How to send POST request to remote URL using VB6 ?
问题:
回答1:
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
回答2:
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