I'm trying to modify the Casablanca tutorial to include basic HTTP authentication to access the Prosper API:
auto fileStream = std::make_shared<ostream>();
// Open stream to output file.
auto requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
{
*fileStream = outFile;
// Create http_client to send the request.
http_client_config config;
credentials creds( "username", "password" );
config.set_credentials( creds );
http_client client( U( "https://api.prosper.com/" ), config );
// Build request URI and start the request.
uri_builder builder(U("/api/Listings/"));
return client.request( methods::GET, builder.to_string() );
})
...
Unfortunately, I keep getting error 401 - unauthorized. However, I can access the page in the browser via https://username:password@api.prosper.com/api/Listings/
, and I can use Casablanca to get to regular web pages that don't need authentication.
I'm new to REST and web stuff in general, and the documentation is useless - http_client_config
is "used to set the possible configuration options." No kidding. I'm not even sure if I'm using the right classes - these things just kind of looked right.
How do I add basic authentication to an http_client request in Casablanca?