请问C++ 使用boost实现http服务端时,在接收form-data中的文件时,
文件超过1mb就会
报错:ec: beast.http:9
message: body limit exceeded
在网上找了几个设置请求体大小的方法没有作用
代码如下:
class http_connection : public std::enable_shared_from_this<http_connection>
{
public:
http_connection(tcp::socket socket)
: socket_(std::move(socket))
{
}
// Initiate the asynchronous operations associated with the connection.
void
start()
{
read_request();
check_deadline();
}
private:
// The socket for the currently connected client.
tcp::socket socket_;
// The buffer for performing reads.
beast::flat_buffer buffer_;
// The request message.
http::request<http::dynamic_body> request_;
// The response message.
http::response<http::dynamic_body> response_;
// The timer for putting a deadline on connection processing.
net::steady_timer deadline_{
socket_.get_executor(), std::chrono::seconds(60 * 20) };
// Asynchronously receive a complete request message.
void read_request()
{
auto self = shared_from_this();
http::async_read(
socket_,
buffer_,
request_,
[self](beast::error_code ec,
std::size_t bytes_transferred)
{
std::cout << "开始读取http接口数据 " << std::endl;
boost::ignore_unused(bytes_transferred);
std::cout << "1 " << std::endl;
if (!ec) {
self->process_request();
std::cout << "2 " << std::endl;
}
std::cout<< "ec: " << ec << std::endl;
std::cout<< "message: " << ec.message() << std::endl;
});
std::cout << "3 " << std::endl;
}
// Determine what needs to be done with the request message.
void process_request()
{
std::cout << "选择接口请求方式 "<< request_.method() << std::endl;
response_.version(request_.version());
response_.keep_alive(false);
switch (request_.method())
{
case http::verb::get:
response_.result(http::status::ok);
response_.set(http::field::server, "Beast");
create_response();
break;
case http::verb::post:
response_.result(http::status::ok);
response_.set(http::field::server, "Beast");
create_post_response();
break;
default:
// We return responses indicating an error if
// we do not recognize the request method.
response_.result(http::status::bad_request);
response_.set(http::field::content_type, "text/plain");
beast::ostream(response_.body())
<< "Invalid request-method '"
<< std::string(request_.method_string())
<< "'";
break;
}
write_response();
}