c# - 请求被中止 : Could not create SSL/TLS secure channel

标签 c# asp.net ssl httpwebrequest

我的客户已告知我他们的 SSL 和 Internet Explorer 存在问题。他们说他们在访问 URL 时遇到信任问题。

我正在通过 HTTPS 访问 JSON。该网站位于一台服务器上,我在本地计算机上使用控制台应用程序。我试图绕过 SSL 证书,但是,我的代码仍然失败。

我可以修改 HttpWebRequest 来解决这个问题吗?

我在使用这段代码时遇到了这个错误:

    // You must change the URL to point to your Web server.
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        req.Method = "GET";
        req.AllowAutoRedirect = true;

        // allows for validation of SSL conversations
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };


        WebResponse respon = req.GetResponse();
        Stream res = respon.GetResponseStream();

        string ret = "";
        byte[] buffer = new byte[1048];
        int read = 0;
        while ((read = res.Read(buffer, 0, buffer.Length)) > 0)
        {
            //Console.Write(Encoding.ASCII.GetString(buffer, 0, read));
            ret += Encoding.ASCII.GetString(buffer, 0, read);
        }
        return ret;

最佳答案

我必须启用其他安全协议(protocol)版本才能解决问题:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
        | SecurityProtocolType.Tls11
        | SecurityProtocolType.Tls12
        | SecurityProtocolType.Ssl3;

关于c# - 请求被中止 : Could not create SSL/TLS secure channel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10822509/

相关文章:

c# - 温莎城堡 : Register by Convention with Named part

ios - 从应用程序内访问已安装的配置文件/证书

asp.net - ASP.Net/C#,在页面上的某些控件之间循环?

c# - .NET 应用程序缓存与数据库缓存

asp.net - 使用 Paypal 订阅(Netflix 风格)

java 等同于 c# sslstream(没有 tcp)

multithreading - 来自多个线程的 OpenSSL SSL_read 和 SSL_write

c# - 只有 1 个进程显示事件并行 foreach

c# - 带有可为空参数的 Type.InvokeMember

c# - Windows 窗体 C# "Input string was not in a correct format"