AMM*_*AMM 7 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.
Run Code Online (Sandbox Code Playgroud)
现在,我想知道如何使用curlpp或libcurl实现相同的功能.代码片段确实会有所帮助.
没有使用 Curlpp 的经验,但这就是我使用 libcurl 的方法。
您可以使用设置目标网址
curl_easy_setopt(m_CurlPtr, CURLOPT_URL, "http://urlhere.com/");
Run Code Online (Sandbox Code Playgroud)
POST 值存储在一个链接列表中——您应该有两个变量来保存该列表的开头和结尾,以便 cURL 可以向其中添加值。
struct curl_httppost* beginPostList;
struct curl_httppost* endPostList;
Run Code Online (Sandbox Code Playgroud)
然后您可以使用以下命令添加此 post 变量
curl_formadd(&beginPostList, &endPostList, CURLFORM_COPYNAME, "key", CURLFORM_COPYCONTENTS, "value", CURLFORM_END);
Run Code Online (Sandbox Code Playgroud)
然后提交就像这样
curl_easy_setopt(m_CurlPtr, CURLOPT_POST, true);
curl_easy_setopt(m_CurlPtr, CURLOPT_HTTPPOST, beginPostList);
curl_easy_perform(m_CurlPtr);
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
归档时间: |
|
查看次数: |
5153 次 |
最近记录: |