以前,我是从站点连接到服务器的。 现在,我使用这些参数从云功能进行连接。 通过忽略自签名证书解决了该问题,但是服务器将状态返回为未授权状态。 为什么? 也许是因为忽略了证书吗?
private static readonly HttpClientHandler httpClientHandler = new HttpClientHandler();
private static readonly HttpClient client = new HttpClient(httpClientHandler);
public static string GetWithAuthorization(string url, string login, string pas, ILogger logger)
{
string uAuth =
Convert.ToBase64String(
Encoding.UTF8.GetBytes(login + ":" + pas)
);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", uAuth);
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
string result = string.Empty;
HttpResponseMessage response = client.GetAsync(url).Result;
//var resp = response.IsSuccessStatusCode;
result = response.Content.ReadAsStringAsync().Result;
return response.StatusCode.ToString();
}