2

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?

Corcus
  • 1,070
  • 7
  • 25
  • 1
    http://stackoverflow.com/a/11420667/95190 Your format isn't valid per spec. Can you change the server? – WiredPrairie Sep 11 '15 at 10:46
  • Thanks for your answer @WiredPrairie . I understand why the HttpClient works that way now. However the server is beyond my control. Do you know of a way to format the Authorization header ommiting the scheme? – Corcus Sep 11 '15 at 14:33

1 Answers1

4

Try:

HttpClient client = new HttpClient();
client.DefaultRequestHeaders.TryAppendWithoutValidation(
    "Authorization",
     "mytoken");
kiewic
  • 15,852
  • 13
  • 78
  • 101