我遇到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