向cppnet-lib响应对象添加一个标头
Add a header to a cppnet-lib response object
我想添加一个标题到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 (build as Release)
- 增加1.55
- cppnet-lib: 0.11.0
任何帮助将非常感激!谢谢。
首先,我认为您使用了错误的文档,因为您使用的是0.11.0版本(我建议您使用0.11.1,它在0.11.0的基础上修复了许多错误)。下面是您实际需要的0.11.0文档的链接:
http://cpp-netlib.org/0.11.0/reference/http_server.html响应对象
第二,您想要直接向响应对象的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
}
// ...
};
相关文章:
- 从 .lib 文件创建一个.dll文件
- 是否可以将 EXE 文件作为 lib 文件链接到另一个项目?
- 从c#lib返回一个包含字符串到c 程序的结构
- 在使用 bazel 构建一个简单的应用程序时,得到错误在 '/usr/lib/java/jdk1.8.0_74/bin/java' 找不到 java
- Android Studio使用JNI来构建C/C ,但是C/C 需要另一个lib.a,如何解决
- buildroot:仅构建一个包裹作为共享和静态lib,所有其他包装仅共享
- 未解决的外部符号,带有静态lib,它使用了另一个静态lib
- 如果C 共享LIB会在C项目中引发一个exeption,会发生什么
- 为什么Visual Studio需要一个静态库(.lib)进行动态链接
- 我需要分发一个头文件和一个带有DLL的lib文件吗
- 为什么视觉工作室会创建一个.LIB 以及.DLL
- 如何使用C++Lib函数或Windows API在一个会话中执行多个cmd命令
- 从.lib到另一个.lib的依赖关系
- 是否可以使用clang-cl在windows上生成一个.lib文件
- 是否有一个c++源/lib来解决2D Bin Packing使用矩形Bin(而不是正方形)和旋转
- 如何创建一个具有全局变量的 lib 文件,这些全局变量应该将其信息共享给另一个项目
- *.dll *的兼容性.一个*.VisualStudio和gcc之间的lib *.def
- 我只有一个没有.h和.lib文件的dll文件.如何在vc++中使用它
- 在VS 2012中编译一个静态免费库.lib
- 向cppnet-lib响应对象添加一个标头