How to use credentials in HttpClient in c#?

I had the exact same problem myself. It seems the HttpClient just disregards the credentials set in the HttpClientHandler. The following shall work however: using System.Net.Http.Headers; // For AuthenticationHeaderValue const string uri = “https://example.com/path?params=1”; using (var client = new HttpClient()) { var byteArray = Encoding.ASCII.GetBytes(“MyUSER:MyPASS”); var header = new AuthenticationHeaderValue( “Basic”, Convert.ToBase64String(byteArray)); client.DefaultRequestHeaders.Authorization = header; … Read more