C ++ - 如何使用Curlpp或libcurl发送HTTP post请求

时间:2010-09-03 08:51:10

标签: c++ http libcurl curlpp

我想用c ++发送一个http post请求。似乎libcurl(Curlpp)是要走的路。

现在,这是发送

的典型请求
http://abc.com:3456/handler1/start?<name-Value pairs>

The name values pairs will have:

field1: ABC
field2: b, c, d, e, f
field3: XYZ

etc.

现在,我想知道如何使用curlpp或libcurl实现相同目的。 代码片段确实会有所帮助。

1 个答案:

答案 0 :(得分:3)

没有Curlpp的经验,但这是我用libcurl做的。

您可以使用

设置目标网址
curl_easy_setopt(m_CurlPtr, CURLOPT_URL, "http://urlhere.com/");

POST值存储在链表中 - 您应该有两个变量来保存该列表的开头和结尾,以便cURL可以为其添加值。

struct curl_httppost* beginPostList;
struct curl_httppost* endPostList;

然后,您可以使用

添加此帖子变量
curl_formadd(&beginPostList, &endPostList, CURLFORM_COPYNAME, "key", CURLFORM_COPYCONTENTS, "value", CURLFORM_END);

提交然后就像这样工作

curl_easy_setopt(m_CurlPtr, CURLOPT_POST, true);
curl_easy_setopt(m_CurlPtr, CURLOPT_HTTPPOST, beginPostList); 
curl_easy_perform(m_CurlPtr);

希望这有帮助!

相关问题