Ниже приведен код:
Код: Выделить всё
var client = new System.Net.Http.HttpClient();
var request = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, "https://****");
var authenticationString = $"{CustomerId}:{CustomerPassword}";
var base64EncodedAuthenticationString = System.Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(authenticationString));
request.Headers.Add("Authorization", "Basic " + base64EncodedAuthenticationString);
request.Headers.Add("Cookie", "****");
var collection = new System.Collections.Generic.List();
collection.Add(new("grant_type", "password"));
collection.Add(new("scope", "HC.Request.AllScopes"));
collection.Add(new("username", UserName));
collection.Add(new("password", Password));
var content = new System.Net.Http.FormUrlEncodedContent(collection);
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
string stringResponse = await response.Content.ReadAsStringAsync();
Код: Выделить всё
response.EnsureSuccessStatusCode();
Подробнее здесь: https://stackoverflow.com/questions/786 ... oesnt-work