How to extract http response when using libcurlpp?

Trying to use libcurlpp (C ++ wrapper for libcurl) to publish a form and get an answer. It all works, but I have no idea how to programmatically access the response from the curlpp :: Easy object after the http transaction has completed. Bascially:

#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
...
curlpp::Easy foo;
foo.setOpt( new curlpp::options::Url( "http://example.com/" ) );
foo.setOpt( new curlpp::options::Verbose( true ) );
...many other options set...
foo.perform();  // this executes the HTTP transaction

When this code works because it is Verboseset to true, I see that the response gets output in STDOUT. But how do I access the full answer instead of resetting STDOUT? Curlpp :: Easy has no way to access the answer.

Many hits on Google with people asking the same question, but no answers. The curlpp mailing list is a dead zone, and the curlpp website's API section has been broken down for a year.

+3
source share
2

:

// HTTP response body (not headers) will be sent directly to this stringstream
std::stringstream response;

curlpp::Easy foo;
foo.setOpt( new curlpp::options::Url( "http://www.example.com/" ) );
foo.setOpt( new curlpp::options::UserPwd( "blah:passwd" ) );
foo.setOpt( new curlpp::options::WriteStream( &response ) );

// send our request to the web server
foo.perform();

foo.perform() , , WriteStream().

+9

, curlpp . , example04.cpp.

#include <curlpp/Infos.hpp>

long http_code = 0;
request.perform();
http_code = curlpp::infos::ResponseCode::get(request);
if (http_code == 200) {
    std::cout << "Request succeeded, response: " << http_code << std::endl;
} else {
    std::cout << "Request failed, response: " << http_code << std::endl;
}
0

Source: https://habr.com/ru/post/1792330/


All Articles