问题
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 I'm 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;
回答1:
So how can i extract the cache header from httpResponse?
res.get("Cache-control");
回答2:
In the last try
block the following can be added to print out the headers to screen:
cout << "RESPONSE:";
string name;
string value;
NameValueCollection::ConstIterator i = res.begin();
while(i!=res.end()){
name=i->first;
value=i->second;
cout << name << "=" << value << endl << flush;
++i;
}
来源:https://stackoverflow.com/questions/15991496/poco-cnet-http-get-headers-from-response