.net - 错误 : Could not create SSL/TLS secure channel Windows 8

标签 .net ssl httpwebrequest windows-8.1

升级到 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 The request was aborted: Could not create SSL/TLS secure channel.

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

最佳答案

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;
}

关于.net - 错误 : Could not create SSL/TLS secure channel Windows 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20228656/

相关文章:

C# HttpWebRequest 响应错误(401)

c# - 如何通过鼠标和按键事件确定 TreeView 上的节点

c# - 是否有辅助方法来解析类似 appSettings 的 xml?

ssl - 将 www.*.example.com 重定向到 *.example.com

c++ - OpenSSL 文件传输

apache - 我们可以在 apache 中向 http 请求注入(inject)请求参数吗

javascript - 如何显示 HTTP 401 基本身份验证对话框

c# - 哪个是首选 : new Nullable<int> or (int? )null?

c# - 使用动态类型而不是不可能的通用属性

java - 服务器证书哈希码在 Java 版本之间发生变化