I am having some trouble understanding the cpp netlib documentation.

member name  type               description
headers      vector<header>     Vector of headers.

A header is a struct of type response_header<http::tags::http_server>. 
An instance always has the members name and value both of which are of type string_type.
string_type is boost::network::string<http::tags::http_server>::type.

In my code when I try to access the headers:

http_server::response_header headers[] = request.headers;

the above doesn't compile. I understand this might seem pretty basic, but I am new to c++. Can anyone guide me on how to iterate through the headers from request?

有帮助吗?

解决方案 2

I figured out the solution, for the sake of anyone else googling this. It seems that the documentation is wrong. Request_header should be used when parsing a request not response header

其他提示

class handler;
typedef http::async_server<handler> server;
for (server::request::vector_type::iterator it = request.headers.begin(); it != request.headers.end(); ++it) {
    printf("%s: %s", it->name.c_str(), it->value.c_str());
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top