Question

Somehow I send the request but the content still looks weird it seems as it isnt decoded but the response contains the following: Content-Encoding: gzip

I tried to manually decode the response,but that didnt worked. Thank for your help :)

void Client::load_login_page()
{
using namespace Poco;
using namespace Poco::Net;

URI uri(constants::url::main_url);
//HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPClientSession session("127.0.0.1", 8888);//Support Fiddler

std::string path(uri.getPathAndQuery());
if (path.empty()) 
    path = "/";

// send request
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
req.set("User-Agent",constants::url::user_agent);
req.add("Accept", "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/    x-xbitmap, */*;q=0.1");
req.add("Accept-Encoding","gzip,deflate");
req.setHost(uri.getHost(),uri.getPort());

session.sendRequest(req);

// get response
HTTPResponse res;
std::cout << res.getStatus() << " " << res.getReason() << std::endl;


std::cout << res.getContentType() << std::endl;
auto iter = res.begin();

while(iter != res.end())
{
    std::cout << iter->first << " : " << iter->second << std::endl;
    iter++;
}




std::istream &is = session.receiveResponse( res );
std::stringstream ss;
StreamCopier::copyStream( is, ss );

std::cout << ss.str() << std::endl;
}
Was it helpful?

Solution

To decompress the gzip encoded response, you can use the filter stream wrapper provided in POCO.

In your header:

#include "Poco/InflatingStream.h"

Then, construct the Poco::InflatingInputStream with the std::istream and compression type:

std::istream &is = session.receiveResponse( res );
std::stringstream ss;
Poco::InflatingInputStream inflater(is, Poco::InflatingStreamBuf::STREAM_GZIP);
StreamCopier::copyStream( inflater, ss );

std::cout << ss.str() << std::endl;
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top