Home > other >  308 Status code when making http request with httplib cpp
308 Status code when making http request with httplib cpp

Time:08-25

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?

CodePudding user response:

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

  •  Tags:  
  • c
  • Related