c++ libcurl - 使用前一个 curl 的响应作为另一个 curl 的参数

标签 c++ json libcurl

我正在使用 C++ libcurl 将数据发布到网络服务,一切正常。我想使用 web 服务响应 (Json) 作为参数在另一个 web 服务中进行另一个 POST。你们能帮帮我吗?非常感谢

//FIRST POST
curl_easy_setopt(curl, CURLOPT_URL, url1.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postData.c_str());
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
std::unique_ptr<std::string> httpResponse1(new std::string());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, httpResponse1.get());
curl_easy_perform(curl);

//SECOND POST
curl_easy_setopt(curl, CURLOPT_URL, url2.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, httpResponse1);
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
std::unique_ptr<std::string> httpResponse2(new std::string());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, httpResponse2.get());
curl_easy_perform(curl);

最佳答案

我建议阅读此类工作并将其基于具有您所需内容的公共(public) libcurl 示例:

  1. 在内存中接收:getinmemory.c

  2. 从内存中 POST(并在内存中接收该响应):postinmemory.c

关于c++ libcurl - 使用前一个 curl 的响应作为另一个 curl 的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55102822/

相关文章:

c++ - 如何沿任意轴缩放对象(在 3D 空间中)

c++ - 直接访问指针是否比通过结构访问指针更快?

java - 使用Gson将json字符串解析为对象

c++ - 为什么 Makefile 找不到包含目录

c++ - 在这种情况下如何从结构中输入字符串数组?

arrays - 如何在 Bash 中将字符串列表转换为 JSON 字符串数组?

json - 使用 jq 从每个主要节点版本获取最新版本

audio - Libcurl发送音频文件

apple-push-notifications - 我必须使用 HTTP/2.0 发送 Apple 推送通知吗?我可以使用 libcurl 吗?

c - 对符号 'CERT_GetDefaultCertDB@@NSS_3.2' 的 undefined reference