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.
You could try:
request.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", token));
as mentioned in https://msdn.microsoft.com/en-us/library/hh875106(v=vs.118).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With