Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using HttpClient, send an Authorization token with no schema

Note: This question is similar to this one, but its suggested answer doesn't apply here.

I am trying to access this API, which is looking for a header that looks like this:

Authorization: {token}

Note the absence of any authentication scheme.

I have tried doing:

myHttpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("", authToken);

Which resulted in an ArgumentException saying that I can't pass an empty string.

I have also tried both:

myHttpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(authToken);

and

myHttpClient.DefaultRequestHeaders.Add("Authorization", authToken);

Both of which result in a FormatException.

There seems to be something forcing me to conform to a standard format for my authorization header, but the service I am trying to access doesn't use that standard format.

like image 850
Jacob Avatar asked Jul 01 '17 17:07

Jacob


1 Answers

You could try:

request.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", token));

as mentioned in https://msdn.microsoft.com/en-us/library/hh875106(v=vs.118).aspx

like image 67
Esra Avatar answered Sep 20 '22 12:09

Esra