Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

308 Status code when making http request with httplib cpp

I am trying to make an HTTP request with httplib cpp to the following endpoint: http://api.publicapis.org/entries. I’m using the following code:

httplib::Client cli("http://api.publicapis.org");

if (auto res = cli.Get("/entries")) {
    if (res->status == 200) {
        std::cout << res->body << std::endl;
    }
} else {
    auto err = res.error();
    std::cout << "HTTP error: " << httplib::to_string(err) << std::endl;
}

The body won’t log, as I am receiving status code 308. Where is the issue?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Http 308 is code for permanent redircect, the page has moved…

Check the Location header in the response and try with this url.

The lib seems to have an option to follow redirects, try setting client.set_follow_location(true);

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading