Search code examples
windows-runtimewindows-8.1uwpwinrt-httpclient

Windows.Web.Http.HttpClient Authorization header without scheme.


I have a winrt app and a Windows.Web.Http.HttpClient

I want to set its Authorization header without using a scheme. My code is as below.

HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("Scheme", "mytoken");

This will result in this Authorization: Scheme mytoken

What I want is this Authorization: mytoken

The problem is that the Constuctor of HttpCredentialsHeaderValue has to take a scheme argument and that scheme cannot be String.empty

Is there a way I can achieve this result?


Solution

  • Try:

    HttpClient client = new HttpClient();
    client.DefaultRequestHeaders.TryAppendWithoutValidation(
        "Authorization",
         "mytoken");