我想在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实现相同的目标。代码片段确实会有所帮助。

有帮助吗?

解决方案

没有curlpp的经验,但这就是我与libcurl做的。

您可以使用目标URL设置

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

帖子值存储在链接列表中 - 您应该有两个变量来保留该列表的开始和结束,以便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);

希望这可以帮助!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top