Poco c ++ Net:Http从响应中获取头 [英] Poco c++Net: Http get headers from response
问题描述
我使用POCO C ++ Net库为http
我想尝试制定持久缓存的策略:
首先,我想我需要从缓存头中过期,并交叉检查缓存的值(请告诉我,如果错了)。
那么如何从httpResponse提取缓存头?
我已经看到你可以在java中执行此操作, getFirstHeader(),但是我怎么做在POCO C ++下面是使用POCO的普通http GET请求:
try
{
//准备会话
URI uri(http://www.google。 se);
HTTPClientSession会话(uri.getHost(),uri.getPort());
//准备路径
string path(uri.getPathAndQuery());
if(path.empty())path =/;
//发送请求
printnet(path.c_str());
HTTPRequest req(HTTPRequest :: HTTP_GET,path,HTTPMessage :: HTTP_1_1);
session.sendingRequest(req);
//获取响应
printnet(Get response);
HTTPResponse res
cout<< res.getStatus()<< < res.getReason()<< endl
//打印响应
istream& is = session.receiveResponse(res);
StreamCopier :: copyStream(is,cout);
}
catch(Exception& ex)
{
printnet(ex.displayText()。c_str());
return -1;
}
return 0;
}
res.get(Cache-control);
Im using POCO C++ Net libraries for http
I want to try make a strategy for persistent caching:
First of all i think i need to get expires from the cache headers and cross check with cached values (please tell me if im wrong).
So how can i extract the cache header from httpResponse?
I've seen that you can do this in java, getFirstHeader(), but how do i do it in POCO C++ Below is an ordinary http GET-request using POCO:
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");
这篇关于Poco c ++ Net:Http从响应中获取头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!