使用cpp-netlib的异步客户端响应
Async client response with cpp-netlib?
我正在考虑为一个新项目使用cpp-netlib。所有的例子都显示了以阻塞的方式读取响应的主体:
client::response response_ = client_.get(request_);
std::string body_ = body(response_);
如果我用async标签构造我的客户端对象:
basic_client<http_async_8bit_udp_resolve_tags, 1, 1> client_();
这有什么影响?
是否可以将body
包装器的结果作为boost::shared_future<std::string>
?
我只需要将阻塞调用封装在它自己的线程中吗?
查看当前http客户端文档:http://cpp-netlib.org/0.12.0/reference/http_client.html
- http客户端现在默认情况下总是异步的
-
您可以选择在
get
或post
调用中提供回调函数或对象:struct body_handler { explicit body_handler(std::string & body) : body(body) {} BOOST_NETWORK_HTTP_BODY_CALLBACK(operator(), range, error) { // in here, range is the Boost.Range iterator_range, and error is // the Boost.System error code. if (!error) body.append(boost::begin(range), boost::end(range)); } std::string & body; }; // somewhere else std::string some_string; response_ = client_.get(request("http://cpp-netlib.github.com/"), body_handler(some_string));
-
client::response
对象已经封装了future
对象:
响应对象封装了一旦值可用就会填充的期货。
相关文章:
- "unknown ca"自生成的 CA、证书和客户端/服务器
- 如何将函数集合传递给客户端类,以便将它们当作客户端类本身的成员使用
- 使用调试/崩溃报告将应用程序部署到客户端
- 如何在本地机器上运行c++和javascript客户端代码(hackerbank风格)
- 如何通过套接字将文本文件的内容从服务器发送到客户端
- 当服务中的事件被触发时,如何将响应从服务发送回客户端?
- 为什么 JsonCpp http 客户端在 201 响应代码上失败?
- 异步WT :: HTTP ::客户端响应和请求匹配
- 使用cpp-netlib的异步客户端响应
- 从Poco http客户端获取对字符串的响应
- 如何使用 NModbus4 框架向 Modbus 客户端发送响应
- 服务器不使用 select(), cpp 响应新客户端
- 提升 Daytime7 服务器示例不响应 NetCat 客户端
- 如何解决从客户端接收消息时窗口冻结问题(无响应)
- 如何在一个套接字上实现并行请求和响应的非阻塞客户端-服务器通信模型,而不存在数据竞争
- 为什么我的c++ Boost ASIO HTTP客户端返回不完整的响应
- BOOST-ASIO阻塞服务器不响应阻塞客户端
- HTTP 客户端请求响应与 pion-net c++
- c++ socket客户端/服务器端不响应客户端
- 将我的服务器响应char数组转换为wchar_t数组是处理客户端收到的服务器消息的正确方法吗?