在VBA HTTP Post请求中传递参数 [英] Pass Parameters in VBA HTTP Post Request
问题描述
我正在尝试在 http://forums.egullet.org的主搜索栏上发布简单的帖子请求/ 。 (这是一个例子,但我正在尝试构建一个可以与许多人一起工作的工具。)
I'm trying to do a simple post request on the main search bar of http://forums.egullet.org/. (This is one example, but I'm trying to build a tool that will work with many.)
问题是我似乎无法弄明白正确的方法来构造/放置参数,以便服务器处理我的请求。 (我确实收到了回复,但这只是一个页面要求我再次尝试搜索,而不是我在浏览器中搜索时得到的结果。参数字符串是直接从firebug中提取的,所以我很公平确定它是正确的。我只是得到的印象是我没有把它放在正确的位置/正确构造/说出我需要的一切,但我不知道要改变什么。值得注意的是我以前有过这是通过编辑Internet Explorer对象的DOM来实现的,但我正在尝试切换到XMLHTTP,因为它更快/更可靠。感谢您的帮助!
The problem is that I can't seem to figure out the right way to structure/place the parameters such that the server processes my request. (I do get a response, but it's just a page asking me to try the search again, rather than the result I get when I do the search in a browser. The argument string was pulled straight out of firebug, so I'm fairly sure that it's correct. I just get the impression that i'm not putting it in the right place/structuring it correctly/saying everything that I need to, but I don't know what to change. It's worth noting that I previously had this working by editing the DOM of an internet explorer object, but I'm trying to switch to XMLHTTP because it's much faster/more reliable. Thanks for your help!
Sub httpPost()
Dim XMLHTTP
Dim result As String
Dim argumentString
argumentString = "?search_term=eggs&search_app=forums"
Set XMLHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
XMLHTTP.Open "POST", _
"http://forums.egullet.org/index.php?app=core&module=search&do=search&fromMainBar=1", False
XMLHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
XMLHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
XMLHTTP.send argumentString
result = XMLHTTP.responsetext
Set XMLHTTP = Nothing
End Sub
推荐答案
I认为你需要一个带有问号的&符号
I think you need an ampersand where you have a question mark
argumentString = "&search_term=eggs&search_app=forums"
这篇关于在VBA HTTP Post请求中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!