为什么这段代码永远不会执行ServerCertificateValidationCallback
事件处理程序?
ServicePointManager.MaxServicePointIdleTime = 0;
try
{
String url = "https://" + Domain;
HttpWebRequest request = WebRequest.CreateHttp(url);
request.Timeout = 10000;
request.KeepAlive = false;
request.AllowAutoRedirect = true;
request.ProtocolVersion = HttpVersion.Version11;
request.ReadWriteTimeout = 10000;
request.Accept = "text/html, application/xhtml+xml, application/xml; q=0.9, image/webp, */*; q=0.8";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36";
request.GetResponse();
request.ServerCertificateValidationCallback += delegate (object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslError) {
Console.WriteLine("CALLED!");
return false;
};
}
catch
{
Console.WriteLine("ERROR!");
}