Answer the question
In order to leave comments, you need to log in
How to read the entire http request along with the body?
Hello!
I ran into such a problem: I am writing a simple http server, and when a POST request with a body comes to me, the request without the body is read first, and then, separately, the body is read.
So, for example, I have a query like this:
POST / HTTP/1.1
Host: ....
Connection: keep-alive
Content-Length: 11
hello world
void TCPConnection::startReceiving()
{
m_socket.async_receive(boost::asio::buffer(m_buffer),
boost::bind(&TCPConnection::handleReceive, shared_from_this(), _1, _2));
}
...
void TCPConnection::handleReceive(const boost::system::error_code ec, size_t bytesTransferred)
{
if (ec)
return;
handler(&m_buffer.front(), bytesTransferred); // Handler for processing some data.
startReceiving();
}
POST / HTTP/1.1
Host: ....
Connection: keep-alive
Content-Length: 11
hello world
Answer the question
In order to leave comments, you need to log in
async_receive :
The receive operation may not receive all of the requested number of bytes. Consider using the async_read function if you need to ensure that the requested amount of data is received before the asynchronous operation completes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question