我想在cppnet-lib basic_response对象中添加一个标头。但是,我收到了编译错误。
我可以按如下方式向basic_request添加一个标题,编译好了:
boost::network::http::basic_request<boost::network::http::tags::http_server> request;
request << header("test", "test");
但是,对响应对象执行相同操作会收到编译错误:
boost::network::http::basic_response<boost::network::http::tags::http_server> response;
response << header("test", "test");
编译错误:
'headers_container_type': the symbol to the left of a '::' must be a type (header.hpp)
'value_type': is not a member of boost::network::http::basic_response<boost::network::http::tags::http_server> (header.hpp)
syntax error: missing ';' before identifier 'value_type' (header.hpp)
这表明在响应对象上这是不可能的,但是跟随以下页面似乎表明它是。我某处显然出错了!
文档:http://cpp-netlib.org/0.8/reference_http_response.html
我的环境是:
非常感谢任何帮助!感谢。
答案 0 :(得分:0)
首先,我认为您使用的是错误的文档,因为您使用的是版本0.11.0(我建议您使用0.11.1,它在0.11.0之上有很多错误修复)。以下是您实际需要的0.11.0文档链接:
http://cpp-netlib.org/0.11.0/reference/http_server.html#response-object
其次,您需要将标头直接添加到响应对象的headers
成员中。无需使用函数来执行此操作:
struct my_server {
void operator(server::request const& req, server::response & res) {
// do something with the request and/or response
res.headers.push_back(server::response::header("Name", "value"));
// do more things
}
// ...
};