I am using the C++ REST SDK (cpprestsdk) to send an HTTP GET request, but I keep getting a 503 Service Unavailable error. When I make the same request in Postman, it works fine and returns a 200 OK response.
Here is my code:
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
#include <iostream>
using namespace web;
using namespace web::http;
using namespace web::http::client;
int main() {
http_client client(U("https://example.com/api/endpoint"));
http_request request(methods::GET);
try {
auto response = client.request(request).get();
if (response.status_code() == status_codes::OK) {
auto body = response.extract_string().get();
std::wcout << U("Response: ") << body << std::endl;
} else {
std::wcout << U("HTTP Error: ") << response.status_code() << std::endl;
}
} catch (const std::exception& e) {
std::cerr << "Exception: " << e.what() << std::endl;
}
return 0;
}
When I run this, the output is:
HTTP Error: 503
In Postman, I send the same request to the same endpoint with the same headers, and it works correctly (returns 200 OK).
2