且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将 POST 发送到远程 url?

更新时间:2023-01-01 17:26:54

有很多方法可以解决这个问题.您可以使用 WinInet API、WinHTTP API、WinHTTPRequest 或 XMLHTTPRequest.我更喜欢较低级别的 Winsock,你可以在这里阅读它:http://www.vbforums.com/showthread.php?t=334645.在我看来,Winsock 有点复杂,但功能更强大.如果你想做简单和甜蜜,XML HTTP 请求是要走的路,我也在 javascript 中使用它.尝试类似:

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

和 OnReadyStateChange 函数:

And the OnReadyStateChange function:

Dim HttpResponse As String

HttpResponse = myMSXML.responseText

如果你发现我的代码不起作用,或者你有点困惑,对不起,我现在对 VB 有点生疏了.您可以在此处查看有关 XMLHTTPRequest 的 Microsoft 官方文档:http://msdn.microsoft.com/en-us/library/ms759148%28VS.85%29.aspx

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