c++ - 如何从响应中只读取正文

标签 c++ boost-beast

我看到的阅读响应的示例如下所示。但这会打印出响应 header 和响应主体。 Beast 是否公开了一种将 body 作为字符串获取的方法?看起来可以访问 res.body,但我不确定如何获取并转换它。

// Declare a container to hold the response
http::response<http::dynamic_body> res;

// Receive the HTTP response
http::read(socket, buffer, res);

// Write the message to standard out
std::cout << res << std::endl;

最佳答案

使用htpp::string_body代替http::dynamic_body然后得到res.body

关于c++ - 如何从响应中只读取正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46627481/

相关文章:

java - Qt中Java窗体布局的模拟

c++ - 如何将元素移动到 vector 的末尾?

c++ - 您如何使用 boost/beast 从 HTTP POST 请求中解析和提取有效负载?

c++ - bad_weak_ptr 同时使用从 boost::asio::io_context::service 继承的类

c++ - 我需要做什么才能使 Boost.Beast HTTP 解析器找到正文的结尾?

c++ - 将迭代器作为 3 个元素的滑动窗口,可以越过边界(可能使用 Boost)

c++ - 我得到一个没有被忽略的无效值,因为它应该是错误的,为什么?

c++ - 免费堆腐败(...)

c++ - "Body requirements not met"将请求传递给 c++ 中的方法(Boost Beast 库)

c++ - 使用 Boost Beast 通过代理发出同步 http 请求时出现问题