elnormous / HTTPRequest

Single-header C++ HTTP request class
The Unlicense
942 stars 213 forks source link

issue #55

Open ghost opened 2 years ago

ghost commented 2 years ago

how can i get web page body as string ?

Altman-conquer commented 2 years ago

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

Eng-MohamedHussien commented 11 months ago

@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;
}