希望有人能够帮助解决这个问题。最近,我们的机器更新了KB4344167,其中包括.NET 4.7.1的安全更新。不幸的是,这个更新破坏了我们的Webrequest代码。当我们运行下面的代码时,会出现以下错误:
当从计算机中卸载安全更新后,代码可以正常执行。我们在上面的代码中是否遗漏了什么?这是我能想到的唯一问题。
任何帮助都将不胜感激!
请求被中止: 无法创建 SSL/TLS 安全信道。
// Create a request for the URL.
WebRequest request = WebRequest.Create(url);
//specify to use TLS 1.2 as default connection
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
request.Timeout = int.Parse(configmanager.GetSetting("Webtimeout"));
// Set proxy
request.Proxy = WebRequest.DefaultWebProxy;
request.Proxy.Credentials = CredentialCache.DefaultCredentials;
// Define a cache policy for this request only.
HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
request.CachePolicy = noCachePolicy;
ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) => true;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
当从计算机中卸载安全更新后,代码可以正常执行。我们在上面的代码中是否遗漏了什么?这是我能想到的唯一问题。
任何帮助都将不胜感激!
ServicePointManager.SecurityProtocol
在Create()
调用期间被访问或复制。在此之后更改它应该没有明显的影响(无论在应用任何修复程序之前还是之后)。 - Damien_The_Unbeliever