不知何故,我发送了请求,但内容看起来仍然很奇怪,因为它没有被解码,但响应包含以下内容: Content-Encoding: gzip
我试图手动解码响应,但没有奏效。感谢您的帮助 :)
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;
}