我尝试过以下C#代码,但在调用GetAsync()时会出现异常。使用具有相同请求的Firefox我能够得到回复。任何想法如何使代码在C#中工作?服务器很旧,不受我的控制。
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
var credentials = new NetworkCredential("user", "password");
var handler = new HttpClientHandler { Credentials = credentials };
var client = new HttpClient(handler);
var url = $"https://ipadress/query";
HttpResponseMessage httpResponseMessage = await client.GetAsync(url);
if (httpResponseMessage.IsSuccessStatusCode)
{
//
}