On Wed, Apr 27, 2011 at 7:01 AM, Antoine Tremblay <he...@gm...> wrote:
> Hi,
Hi Antoine,
I'd like to point you to the new discussion group:
https://groups.google.com/group/cpp-netlib where you should be posting
further questions. I've CC'ed the new group to this response -- you'll
have to subscribe to that list too so that we can continue the
conversation over there instead.
> I'm trying to use cpp-netlib 0.9 to implement a simple client.
> But I'm having trouble getting a response header , I've read the example
> http_client.cpp.
> In that example you use an iterator to print all the headers.. however I saw
> in :
> headers.cpp :
> struct response_headers_wrapper { ...
> range_type operator[] (string_type const & key) const {
> return message_.headers().equal_range(key);
> }
> I would like to use the headers wrapper to call directly like :
> using namespace boost::network;
> typedef http::basic_client<http::tags::http_default_8bit_tcp_resolve, 1,
> 1> http_client;
> http_client client;
> std::string req_str = "http://localhost/";
> http_client::request request(req_str);
> request << header("Connection", "close");
> http_client::response response = client.get(request);
> This section here is my problem :
> headers_range<http_client::response>::type headers OR
> basic_response<Tag>::headers_container_type = response.headers(); ???
> const string<tags::default_string>::type cookie_header("Set-Cookie");
> TYPE ?? = headers[cookie_header]
> But really I'm having a hard time figuring out the correct types... with the
> tags etc.. Still quite new to me.
> Especially the range_type.. I got a feeling it should return
> a basic_response<Tag>::headers_container_type .. and that should be the
> wrapper? But i'm not sure what the tag should be.. or anyway I feel quite
> lost.
No, the range_type is a Boost.Range iterator range. You'd want to read
up on Boost.Range from http://www.boost.org/libs/range -- the way it
would be used is this way:
typedef typename headers_range<http_client::response>::type
headers_range_type;
range_type cookie_range = headers(response)["Set-Cookie"];
No special tags you need to worry about. ;) Once you have the range,
you can then deal with it like any Boost.Range:
BOOST_FOREACH(http_client::response::header_type const & header,
cookie_range) {
// header.name and header.value now usable in this context
}
Or something to that effect -- I'm doing this from memory so I may
have gotten a few things wrong. :D
> A simple example that would illustrate how to get a std::string for a
> specific header would help me to understand quite a lot
>
That above should help.
Cheers!
--
Dean Michael Berris
http://about.me/deanberris
|