.NET 请求被中止:无法创建 SSL/TLS 安全通道
Posted
技术标签:
【中文标题】.NET 请求被中止:无法创建 SSL/TLS 安全通道【英文标题】:.NET The request was aborted: Could not create SSL/TLS secure channel 【发布时间】:2014-12-26 14:21:29 【问题描述】:我已经尝试了我遇到的所有可能的解决方案,但似乎没有任何效果。以下是提取的跟踪日志(一个用于尝试与 Paypal 通信,另一个用于尝试与 GetSentry 通信):
System.Net Information: 0 : [10776] SecureChannel#49633458::.ctor(hostname=svcs.sandbox.paypal.com, #clientCertificates=0, encryptionPolicy=RequireEncryption)
System.Net Information: 0 : [10776] SecureChannel#49633458 - Left with 0 client certificates to choose from.
System.Net Information: 0 : [10776] Using the cached credential handle.
System.Net Information: 0 : [10776] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = (null), targetName = svcs.sandbox.paypal.com, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [10776] InitializeSecurityContext(In-Buffer length=0, Out-Buffer length=58, returned code=ContinueNeeded).
System.Net Information: 0 : [10776] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = 69e8d930e0:cc64028eb0, targetName = svcs.sandbox.paypal.com, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [10776] InitializeSecurityContext(In-Buffers count=2, Out-Buffer length=0, returned code=IllegalMessage).
System.Net Error: 0 : [10776] Exception in HttpWebRequest#2657604:: - The request was aborted: Could not create SSL/TLS secure channel..
System.Net Error: 0 : [10776] Exception in HttpWebRequest#2657604::GetResponse - The request was aborted: Could not create SSL/TLS secure channel..
System.Net Information: 0 : [10776] SecureChannel#39602548::.ctor(hostname=app.getsentry.com, #clientCertificates=0, encryptionPolicy=RequireEncryption)
System.Net Information: 0 : [10776] SecureChannel#39602548 - Left with 0 client certificates to choose from.
System.Net Information: 0 : [10776] Using the cached credential handle.
System.Net Information: 0 : [10776] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = (null), targetName = app.getsentry.com, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [10776] InitializeSecurityContext(In-Buffer length=0, Out-Buffer length=58, returned code=ContinueNeeded).
System.Net Information: 0 : [10776] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = 69e8d930e0:cc64029510, targetName = app.getsentry.com, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [10776] InitializeSecurityContext(In-Buffers count=2, Out-Buffer length=0, returned code=IllegalMessage).
System.Net Error: 0 : [10776] Exception in HttpWebRequest#49716141:: - The request was aborted: Could not create SSL/TLS secure channel..
System.Net Error: 0 : [10776] Exception in HttpWebRequest#49716141::GetResponse - The request was aborted: Could not create SSL/TLS secure channel..
我试过了
ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, sslPolicyErrors) => true;
以及(Global.asax.cs 中的 Application_Start)
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
似乎没有任何帮助。这是在 MVC 应用程序中的 Windows 8.1 Pro 机器上。
【问题讨论】:
【参考方案1】:看起来我使用的 SharpRaven 库版本将 ServicePointManager.SecurityProtocol
强制转换为 SSL3,从而破坏了任何后续调用。新的库版本没有这样做,但我仍然在执行我的调用之前将其显式设置为 TLS,只是为了更好地衡量。
【讨论】:
我遇到了同样的模棱两可的错误,最后 ServicePointManager.SecurityProtocol 被设置为端点不支持的值。请将此标记为答案。以上是关于.NET 请求被中止:无法创建 SSL/TLS 安全通道的主要内容,如果未能解决你的问题,请参考以下文章
请求被中止:无法创建 SSL/TLS 安全通道。System.Net.WebException
条纹支付:System.Net.WebException:请求被中止:无法创建 SSL/TLS 安全通道
Azure w/TLS/SNI 上的 .net httpclient:请求被中止:无法创建 SSL/TLS 安全通道
使用 HtmlAgilityPack 进行 Web 查询抛出 System.Net.WebException:请求被中止:无法创建 SSL/TLS 安全通道 [重复]