0

I am currently looking for a way to send a POST-request via casablanca/C++ Rest SDK.

It's for the reddit API, and I am supposed to send 3 pairs of value in my POST data, as well as 2 pairs with my header.

I know that I can add values to my header like this:

web::http::http_request authRequest(web::http::methods::POST);
authRequest.headers().add(L"client_id", <code>);
authRequest.headers().add(L"client_secret", <secret>);

Also, I know how to attach POST data:

web::http::client::http_client client(<url>); 
web::json::value postData;
client.request(methods::POST, <parameter>, postData , <parameter>);

However, I don't know how to merge both into one request.

I have the feeling I can do it all with version 2, while passing my header data as some kind of parameter, but I can't quite figure out how. I've been reading up on the documentation, but every parameter says something like "Put this data in here, and that data in here", so I'm getting confused what to pass at which point.

Also I'm not too experienced with vocabulary in this aspect of network programming, so I can't quite figure it out myself.

I'd be happy to get some advice on this!

Sossenbinder
  • 4,852
  • 5
  • 35
  • 78

1 Answers1

1

The http_request object has a method set_body() that lets you set the POST data. In your examples, this would look something like

authRequest.set_body(postData);

reference doc

roschuma
  • 536
  • 4
  • 7