Watson
Watson

Reputation: 1425

c# Httpclient authorization header without realm

Many services I wish to authenticate with require the following format:

authorization: ZCb8p0CIngLSFrBJgA/BYyUZI8zaj3MPg=

If you add a realm in front of the request, it no longer works.

authorization: basic ZCb8p0CIngLSFrBJgA/BYyUZI8zaj3MPg= //doesn't work

Yet, in c# the basic httpclient, I can't add a request header authorization without adding a realm. It always throws an exception, is there a way to add the request authorization header with no realm?

Throws error but this authenticates:

request.Headers.Add("Authorization", "ZCb8p0CIngLSFrBJgA/BYyUZI8zaj3MPg=");

Doesn't throw an error but does not authenticate:

request.Headers.Add("Authorization", "basic ZCb8p0CIngLSFrBJgA/BYyUZI8zaj3MPg=");

Upvotes: 0

Views: 353

Answers (1)

Watson
Watson

Reputation: 1425

client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", String.Format("example;{0}", value));

HttpClient Authorization Header Invalid Format

Upvotes: 1

Related Questions