【问题标题】:Error: Could not create SSL/TLS secure channel Windows 8错误:无法创建 SSL/TLS 安全通道 Windows 8
【发布时间】:2013-11-30 07:28:14
【问题描述】:

升级到 Windows 8 后,我遇到了以前正常工作的 Web 服务调用问题。我已经在两台 Windows 8.1 机器和一台 Windows 8 机器上验证了以下代码失败,但它在 Windows 7 和 Windows Server 2008 R2 上正常工作。

var uriString = "https://secure.unitedmileageplus.com/";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriString);

try {
    using(WebResponse response = request.GetResponse()) {
        response.Dump();
    }
}
catch(Exception e) {
    e.Dump();
}

WebException 请求被中止:无法创建 SSL/TLS 安全 频道。

它似乎已本地化到此端点,因为我能够成功地对其他 URL 进行 SSL 调用。我已经做了一些 Wireshark 嗅探,但不知道要寻找什么,这并没有太大帮助。如果您希望我也提供这些日志,请告诉我。

【问题讨论】:

    标签: .net ssl httpwebrequest windows-8.1


    【解决方案1】:

    WebRequest 默认将 TLS/SSL 版本设置为 TLS 1.0。您可以使用ServicePointManager.SecurityProtocol 将其设置回 SSL 3.0。例如:

    static void Main(string[] args)
    {
        var uriString = "https://secure.unitedmileageplus.com/";
    
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriString);
    
        ServicePointManager.ServerCertificateValidationCallback =
            new RemoteCertificateValidationCallback(AcceptAllCertifications);
    
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
    
        try
        {
            using (WebResponse response = request.GetResponse())
            {
                Debug.WriteLine(response);
            }
        }
        catch (Exception e)
        {
            Debug.WriteLine(e);
        }
    }
    
    public static bool AcceptAllCertifications(
        object sender,
        System.Security.Cryptography.X509Certificates.X509Certificate certification,
        System.Security.Cryptography.X509Certificates.X509Chain chain,
        SslPolicyErrors sslPolicyErrors)
    {
        return true;
    }
    

    【讨论】:

    • SSL3 已被弃用,因此使用时要小心!
    猜你喜欢
    • 2018-04-06
    • 2017-05-25
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 2014-12-26
    • 2017-02-10
    相关资源
    最近更新 更多