Answer the question
In order to leave comments, you need to log in
Why is the HTTP response body empty?
Hello! Used boost::beast and decided to get the HTML page en.wikipedia.org/wiki/HTTP. But when after sending the request, the response came with an empty body. What is the problem?
#include <iostream>
#include <boost/beast.hpp>
using namespace boost::beast;
int main()
{
// Подключение к серверу
net::io_context io;
net::ip::tcp::socket socket(io);
net::ip::tcp::resolver resolver(io);
net::connect(socket, resolver.resolve("ru.wikipedia.org", "80"));
// Отправка запроса
http::request<http::empty_body> request(http::verb::get, "/wiki/HTTP", 11);
request.set(http::field::host, "ru.wikipedia.org");
request.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);
http::write(socket, request);
// Чтение ответа
std::string string_response;
{
flat_buffer buffer;
http::response<http::dynamic_body> response;
http::read(socket, buffer, response);
string_response = buffers_to_string(response.body().data());
}
// На консоль выводится пустая строка
std::cout << string_response << std::endl;
socket.shutdown(net::ip::tcp::socket::shutdown_both);
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question