HttpClient authorization error on linux machine

This is my simple spike code:

var url = "";
var username = "user";           
var password = "password";           

var client = new HttpClient();

var base64 = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64);

var result = client.GetAsync(url).Result;

On my Ubuntu server I always get a 401 authentication error with this code. When I fire the webservice data on the same machine with Postman, the call works.

If I run the code directly on the webservice server (Windows Server) itself, the call works too.

What can be the problem? Firewall is disabled.

1 answer

  • answered 2020-03-31 14:22 user3384512

    I found the problem. For whatever reason, the call via the code only works over HTTPS.