Simple example, of documentation to access http server with basic authentication

Jun 10, 2014 at 4:23 AM

I'm trying to download a file from a server that uses username and password to limit access to its resources.

I've reviewed the examples for Facebook and Windows live, but I think that they are not applicable to a "normal" website

Using the web browser the process is:
1) Welcome page: enter username and password
2) Download the file

Can I do the same using Casablanca?, can you please give me an example?. Currently I received and error code 401 when I run this code:
int _tmain(int argc, _TCHAR* argv[])
    auto fileName = L"D:\\sample.xml";

    web::http::uri_builder uribuilder(L"");
    http_client_config config;
    config.set_credentials(credentials(L"user", L"password"));
    http_client client(uribuilder.to_uri(), config);

    client.request(methods::GET).then([=](http_response response){
        return response.body();
    }).then([=](streams::istream is){
       streams::streambuf<uint8_t> rwbuf = file_buffer<uint8_t>::open(fileName).get();

    return 0;
Jun 13, 2014 at 7:31 PM
Hi azcar

Your code looks perfect. This is exactly how we validate basic authentication in our tests, so I am not sure what is wrong.
Do you have access to the server, by any chance is it possible to verify if the server is receiving the credentials that are being sent or is it receiving the currently logged in user's credentials.

Jul 21, 2014 at 6:08 AM
Hi Kavya,

sorry for the delay, I had an accident and I was off several weeks.

I tested again, and its working fine.