Search code examples
c++boost-beast

How to read only body from response


The examples of reading the response that I've seen look something like the following. But this prints out the response header as well as the response body. Does Beast expose a way to get just the body as a string? I t looks like it is possible to access res.body but I'm not sure exactly how to take that and convert it.

// Declare a container to hold the response
http::response<http::dynamic_body> res;

// Receive the HTTP response
http::read(socket, buffer, res);

// Write the message to standard out
std::cout << res << std::endl;

Solution

  • Use htpp::string_body instead of http::dynamic_body and then get res.body