我遇到libcurl問題。我寫了簡單的程序,應該發佈數據(填寫表格),但程序不工作。 我的形式:使用libcurl發佈數據
...
<div><label for="id_person_name">Your name</label> <input type="text" id="id_person_name" name="name" /></div>
<div></div>
<div class="clear"></div>
<div><label for="id_comment">Comment</label><textarea name="comment" id="id_comment" rows="10" cols="60" class="txt"></textarea></div>
...
計劃:
#include <curl/curl.h>
#include <iostream>
using namespace std;
int main(){
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://examplesite.com");
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=Bjarne&comment=example");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
cout << endl;
}
return 0;
}
當然,我測試此代碼:http://curl.haxx.se/libcurl/c/postit2.html,但它不工作。
任何人都可以幫助我嗎?
能否請你定義「不工作」,它連接了我 – 2012-07-22 20:00:19
所以我會告訴你簡單的例子。我使用http://curl.haxx.se/libcurl/c/http-post.html這個程序,我測試它在這個頁面上:m.se.pl/nc/comments/dodaj/27/269110/我填寫地址 'curl_easy_setopt(curl,CURLOPT_URL,「http://m.se.pl/nc/comments/dodaj/27/269110/");'和 'curl_easy_setopt(curl,CURLOPT_POSTFIELDS,」name = test&comment = test「 );'並編譯它 - 一切正常。我在5秒後開始我的程序。程序顯示我來源這個頁面(當然在添加帖子之前的源代碼)。 – user1518451 2012-07-22 20:16:57
在您提供的網頁上,您還需要包含一些額外的信息,例如security_hash,timesamp,next等(它們是隱藏字段)。您可以在網頁源代碼中看到它們。我想這使服務器拒絕查詢導致沒有網頁返回 – 2012-07-23 16:01:31