GET HTTP request with credentials always returns 401 on Mac OSX

Sep 4, 2014 at 12:18 PM
Edited Sep 4, 2014 at 12:40 PM
We wrote the following code for GET requests which need setting of credentials:
    // ...
    return pplx::create_task([=]
    {
       web::http::client::http_client_config  client_config;
       client_config.set_validate_certificates(false);

       // set credentials
        web::http::client::credentials cred(username, password);
        client_config.set_credentials(cred);

        // create http client
        web::http::client::http_client client(baseURI, client_config);

        // create http request
        web::http::http_request request(method); // method is "GET"
        request.headers().set_content_type(contentType);
        request.set_request_uri(requestURI);

        return client.request(request);}).then([](http_response resp)
        {
            web::http::status_code nStatusCode = resp.status_code();
            // gets status_codes::OK on Windows
            // but status_codes::Unauthorized (401) on Mac OSX
            // ...

            return responseJson;
        });
    // ...
It works fine on Windows but always gets status code 401 on Mac OSX.
Is any workaround to fix this issue?
Coordinator
Sep 4, 2014 at 10:54 PM
Hi ovidiucucu,

We don't currently support HTTP Basic Auth on non-Windows platforms. We do have an open issue for it here: https://casablanca.codeplex.com/workitem/89. If this is important for you, please do vote for it.

We also accept contributions, if you are inclined to implement support yourself.

Sincerely,
roschuma
Sep 5, 2014 at 9:05 AM
Edited Sep 5, 2014 at 9:11 AM
Thank you for the fast answer!
Meanwhile, I found a little workaround: instead of setting the credentials in http_client_config, add Authorization value directly in the request headers.

   request.headers().add(U("Authorization"), U("Basic dXNlcl9uYW1lOnBhc3N3b3Jk"));
where "dXNlcl9uYW1lOnBhc3N3b3Jk" is the Base64 encoding of "user_name:password" (this one is just a hardcoded example).
I'm not sure (being not a WEB programmer) if this can be a universal fix, but at least it works for our needs both on Windows and Mac OSX.

Looking forward for more non-Windows support in Casablanca,
Ovidiu
Marked as answer by roschuma on 9/5/2014 at 2:47 PM