0

我想向 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

我的环境是:

  • Visual Studio 2013(作为发行版构建)
  • 提升 1.55
  • cppnet 库:0.11.0

任何帮助将不胜感激!谢谢。

4

1 回答 1

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
  }
  // ...
};
于 2015-03-24T17:51:56.580 回答