Answer the question
In order to leave comments, you need to log in
What is the correct way to read with boost::asio::read up to a certain character?
Hello!
There is the following C++ code for receiving responses to POST requests:
boost::asio::write(*socket, request);
std::vector<char> response(10 * 1024);
boost::system::error_code ec;
auto bytes_received = boost::asio::read(*socket, boost::asio::buffer(response), boost::asio::transfer_all(), ec);
std::cout << response.data() << std::endl;
Answer the question
In order to leave comments, you need to log in
I would take the data into the buffer and parse it already.
1) as soon as data appears in the socket -> read into the buffer
2) after each read, check if the full HTTP header has formed in the buffer
3) as soon as the header is typed, parse and bite it
4) similarly, we wait in parts, collect and parse JSON
5) we repeat everything from the beginning - we are waiting for a new HTTP header and so on
my proxy is here, where the devil will break his leg
(I doubt that it will help much xD)
Sorry, unfortunately, I could not understand the advice from 15432:
я б принимал данные в буфер и парсил уже его.
1) как только в сокете появляются данные -> читаем в буфер
2) после каждого чтения проверяем, не сформировался ли в буфере полный HTTP заголовок
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question