Using c++ rest SDK to make a GET request including headers / body

492 Views Asked by At

How do I make an http GET request with headers and possibly a body using c++ rest SDK? I'm able to make a GET request without headers / body as follows:

web::http::client::http_client client(U("https://host.com"));
pplx::task<http_response> response = client.request(methods::GET, U("/URL/"));
response.then(...)......

and a POST request works with headers and json body like this:

web::json::value body = web::json::value::object();
web::http::client::http_client client(U("Full URL"));
http_request req(methods::POST);
req.headers().add(U("..."), U("..."));
req.headers().add(U("..."), ...);
//construct body here
req.set_body(body);
auto response = client.request(req).then(...)......

This also works. But everytime I try a GET request and add the headers / body, I get an error with the reponse.

At first I thought it would just be a matter of using the POST method and changing methods::POST to methods::GET but this does not work.

Thanks in advance

EDIT: When just trying to add headers, this is what I originally thought would work:

web::http::client::http_client client(U("Full URL"));
http_request req(methods::GET);
req.headers().add(U("..."), U("..."));
req.headers().add(U("..."), ...);
auto response = client.request(req).then(...)......
0

There are 0 best solutions below