如何将 POST 发送到远程 url? [英] How to send POST to remote url?
问题描述
如何使用 VB6 向远程 URL 发送 POST 请求?
How to send POST request to remote URL using VB6 ?
推荐答案
有很多方法可以解决这个问题.您可以使用 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
这篇关于如何将 POST 发送到远程 url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!