11,568 questions
Hi, does System.Text.Encoding.UTF8.GetBytes(authenticationString)
work for you?
Cheers,
Alex
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi All,
How to use Basic Auth with HttpClient?
I use snippet codes below, but keeps getting 401, what I have missed?
var authenticationString = $"{userName}:{userPassword}";
var base64String = Convert.ToBase64String(
System.Text.Encoding.ASCII.GetBytes(authenticationString));
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64String);
await _httpClient.GetAsync(url);
Hi, does System.Text.Encoding.UTF8.GetBytes(authenticationString)
work for you?
Cheers,
Alex
its one of the following issues