0
我用適當的Poco :: Net :: HTTPRequest使用Poco :: Net :: HTTPClientSession獲取服務器頁面,該工作正常。現在我收到回覆,有時返回的頁面會被壓縮。如何在POCO :: Net :: HTTPResponse對象中獲取內容編碼?
我需要弄清楚什麼時候是這種情況,這樣我可以在必要時放氣。應該指出這一點的HTTP頭是Content-Encoding:gzip;但Poco :: Net :: HTTPResponse中沒有getContentEncoding()方法。
這裏有一個非工作片斷(因爲沒有resp.getContentEncoding()):
// resp is the Poco::Net::HTTPResponse object,
// sess is the Poco::Net::HTTPClientSession
std::istream &in = sess.receiveResponse(resp);
// Get the server-returned body as a string (potentially deflate)
std::ostringstream serveroutput;
if (resp.getContentEncoding() == "gzip") {
Poco::InflatingInputStream
inflater(in, Poco::InflatingStreamBuf::STREAM_GZIP);
Poco::StreamCopier::copyStream(inflater, serveroutput);
} else
Poco::StreamCopier::copyStream(in, serveroutput);
// Now we can get at the body as a string
std::string txt = serveroutput.str();
有誰知道如何在生頭得到的,這樣我可以檢查標題內容編碼自己,或另一種有用的方法來確定服務器響應是否被gzipped?