HttpClient connect with basic authentication


Scenario:

Connect to service using login/password

Solution:

  1. Connect using basic authentication and send message
  2. 1
    2
    3
    4
    5
    6
    7
    8
    9
                var client = new HttpClient();
    
                var bytearray = Encoding.ASCII.GetBytes($"{userName}:{password}");
                client.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue("Basic", Convert.ToBase64String(bytearray));
    
                var response = client.SendAsync(message).Result;
    
                var statusCode = response.StatusCode;

No comments:

Post a Comment

Move Github Sub Repository back to main repo

 -- delete .gitmodules git rm --cached MyProject/Core git commit -m 'Remove myproject_core submodule' rm -rf MyProject/Core git remo...