使用libcurlpp时如何提取http响应?

Sté*_*ane 3 libcurl curlpp

尝试使用libcurlpp(libcurl的C++包装器)发布表单并获取响应.这一切都有效,但我不知道如何在http事务完成后以编程方式访问curlpp :: Easy对象的响应.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
Run Code Online (Sandbox Code Playgroud)

当这段代码运行时,因为Verbose设置为trueI我可以看到响应得到输出到STDOUT.但是如何获得完整的响应而不是将其转储到STDOUT?curlpp :: Easy似乎没有任何方法可以访问响应.

谷歌有很多点击,人们问同样的问题,但没有回复.curlpp邮件列表是一个死区,curlpp网站的API部分已经被打破了一年.

Sté*_*ane 10

这就是我最终做到的方式:

// 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();
Run Code Online (Sandbox Code Playgroud)

一旦foo.perform()返回,现在可以在提供的流中使用完整的响应主体WriteStream().