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

问题描述 投票:0回答:1

我正在使用C ++ libcurl将数据发送到Web服务,一切正常。我想使用webservice响应(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);
c++ json libcurl
1个回答
1
投票

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

  1. 在记忆中收到:getinmemory.c
  2. 从内存中POST(并在内存中接收该响应):postinmemory.c
© www.soinside.com 2019 - 2024. All rights reserved.