我的出发点是从 boost http_client_async 的 boost beast http_client_async 示例创建一个简单的下载器代码。在这种情况下,我想将接收到的正文写入文件。
于是我把字符串body换成了file_body,来写接收到的数据:
http::response_parser<http::file_body> res_;
并简单地将 on_write 方法重写为
void on_write( boost::system::error_code ec,
std::size_t bytes_transferred )
{
boost::ignore_unused(bytes_transferred);
if(ec)
return fail(ec, "write");
boost::system::error_code ec_file;
res_.body().open("myTest.txt", boost::beast::file_mode::write, ec_file);
// test for ec_file missing
// Receive the HTTP response
http::async_read(socket_, buffer_, res_,
std::bind(
&session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
}
所以但是现在,一些接收到的数据体太大了:
read: body limit exceeded
我试着增加身体极限。
如果使用解析器而不是消息,则可以使用该body_limit()
方法更改请求正文的大小限制。
是否也有一种简单的方法可以从消息中增加正文大小限制?