7

我想用 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 实现相同的目标。代码片段真的很有帮助。

4

1 回答 1

4

没有使用 Curlpp 的经验,但这就是我使用 libcurl 的方式。

您可以使用设置目标网址

curl_easy_setopt(m_CurlPtr, CURLOPT_URL, "http://urlhere.com/");

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

struct curl_httppost* beginPostList;
struct curl_httppost* endPostList;

然后,您可以使用添加此 post 变量

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);

希望这可以帮助!

于 2010-09-03T09:03:08.860 回答