我为 http 使用 POCO C++ Net 库
我想尝试为持久缓存制定策略。
首先,我认为我需要从缓存标头中获取过期时间并与缓存值进行交叉检查(如果我错了,请告诉我)。
那么如何从中提取缓存标头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;