簡體   English   中英

C ++ - 如何使用Curlpp或libcurl發送HTTP post請求

[英]C++ - how to send a HTTP post request using Curlpp or libcurl

我想用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做的。

您可以使用設置目標網址

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

希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM