c ++ libcurl-使用先前卷曲的响应作为对另一个卷曲的参数

时间:2019-03-11 13:23:34

标签: c++ json libcurl

我正在使用C ++ libcurl将数据发布到Web服务,并且一切正常。我想使用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);

1 个答案:

答案 0 :(得分:1)

我建议您根据需要的公共libcurl示例阅读并进行此类工作:

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

  2. 从内存中发帖(并在内存中也收到该响应):postinmemory.c