elnormous/HTTPRequest

issue

veraonthium opened this issue · 2 comments

how can i get web page body as string ?

just like this
the result would be the page body
http::Request request{"http://test.com/test"};

@venti-bit @Altman-conquer
General speaking body of a webpage always exists in the HTTP response body.
Check the following example:

#include <iostream>

#include "HTTPRequest.hpp"

int main()
{
    try
    {
        // you can pass http::InternetProtocol::V6 to Request to make an IPv6 request
        http::Request request{"http://info.cern.ch/hypertext/WWW/TheProject.html"};

        // send a get request
        const auto response = request.send("GET");
        std::cout << std::string{response.body.begin(), response.body.end()} << '\n'; // print the result
    }
    catch (const std::exception& e)
    {
        std::cerr << "Request failed, error: " << e.what() << '\n';
    }
    return 0;
}