問題描述
我正在嘗試在 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 think you need an ampersand where you have a question mark
argumentString = "&search_term=eggs&search_app=forums"
這篇關于在 VBA HTTP Post 請求中傳遞參數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!