Poco c Net:Http从响应中获取标题
作者:互联网
我使用POCO C Net库作为http
我想尝试为持久缓存制定策略.
首先,我想我需要从缓存标题中过期并使用缓存值进行交叉检查(请告诉我,如果我错了).
那么如何从httpResponse中提取缓存头?
我已经看到你可以用Java(getFirstHeader()
)做到这一点,但我怎么在POCO C中做到这一点?
以下是使用POCO的普通http GET请求:
try
{
// prepare session
URI uri("http://www.google.se");
HTTPClientSession session(uri.getHost(), uri.getPort());
// prepare path
string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
// send request
printnet(path.c_str());
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
session.sendRequest(req);
// get response
printnet("Get response");
HTTPResponse res;
cout << res.getStatus() << " " << res.getReason() << endl;
// print response
istream &is = session.receiveResponse(res);
StreamCopier::copyStream(is, cout);
}
catch (Exception &ex)
{
printnet(ex.displayText().c_str());
return -1;
}
return 0;
解决方法:
So how can i extract the cache header from httpResponse?
res.get("Cache-control");
标签:http-caching,c,http,poco-libraries 来源: https://codeday.me/bug/20190725/1534845.html