简体   繁体   English

发出请求时出错:请求被中止:无法创建 SSL/TLS 安全通道

[英]Error when making request: The request was aborted: Could not create SSL/TLS secure channel

Here is my codes :这是我的代码:

try {
    HttpWebRequest req = (HttpWebRequest) WebRequest.Create("https://api.coindesk.com/v1/bpi/currentprice.json");
    req.Method = "GET";
    req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8";
    req.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";
    req.ContentType = "text/html; charset=utf-8";
    req.Referer = "";
    req.KeepAlive = true;
    req.Timeout = 25000;
    req.AllowAutoRedirect = true;

    CookieContainer cookieJar1 = new CookieContainer();
    req.CookieContainer = cookieJar1;

    HttpWebResponse res = (HttpWebResponse) req.GetResponse();

    foreach(Cookie cookie in res.Cookies) {
        cookieJar1.Add(new Cookie(cookie.Name.Trim(), cookie.Value.Trim(), "/", cookie.Domain));
    }

    Stream Stream = res.GetResponseStream();
    StreamReader reader = new StreamReader(Stream);
    string reader_str = reader.ReadToEnd();

    var obj = JObject.Parse(reader_str);
    string bitcoin_price_str = ((string) obj["bpi"]["USD"]["rate"]).Trim().Replace(",", "");
    bitcoin_price = double.Parse(bitcoin_price_str);

    reader.Close();
    Stream.Close();
    res.Close();
}
catch(Exception ex_1) {
    Send_Email_Gmail();
}

Before today those codes were working ok.在今天之前,这些代码工作正常。
But today i faced an error about Invalid Certificate Date .但是今天我遇到了关于Invalid Certificate Date的错误。
When i opened that url in browser (FireFox & Chrome) that error was there.当我在浏览器(FireFox 和 Chrome)中打开那个 url 时,那个错误就出现了。
Some hours ago they fixed the issue on their server.几个小时前,他们修复了服务器上的问题。
Now in FireFox & Chrome there is no problem.现在在 FireFox 和 Chrome 中没有问题。
But in my codes i face this error :但在我的代码中,我面临这个错误:

The request was aborted: Could not create SSL/TLS secure channel.请求被中止:无法创建 SSL/TLS 安全通道。

I tried this solution :我试过这个解决方案

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

Not help.没有帮助。
What should i do?我该怎么办?

It seems thatapi.colindesk.com now only supports TLS 1.2 and 1.3 while blockchain.info still supports the deprecated TLS 1.1 . api.colindesk.com 现在似乎只支持 TLS 1.2 和 1.3blockchain.info 仍然支持已弃用的 TLS 1.1

This immediately (to me at least) suggests that you're using old versions of Windows that don't support TLS1.2 by default - confirmed in the comments on the question.这立即(至少对我而言)表明您使用的是默认情况下不支持 TLS1.2 的旧版 Windows - 在问题的评论中得到确认。

There are numerous answers on SO that show how to do this. SO上有很多答案显示了如何做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 服务器错误:请求已中止:无法创建SSL / TLS安全通道 - Server Error: The request was aborted: Could not create SSL/TLS secure channel SChannel 错误:请求被中止:无法创建 SSL/TLS 安全通道 - SChannel error: The request was aborted: Could not create SSL/TLS secure channel 请求已中止:无法创建SSL / TLS安全通道 - SecurityProtocol行为 - The request was aborted: Could not create SSL/TLS secure channel - SecurityProtocol behavior .NET请求已中止:无法创建SSL / TLS安全通道 - .NET The request was aborted: Could not create SSL/TLS secure channel WebException:请求已中止:无法创建SSL / TLS安全通道 - WebException: The request was aborted: Could not create SSL/TLS secure channel 请求已中止:无法创建SSL / TLS安全通道异常 - The request was aborted: Could not create SSL/TLS secure channel Exception HttpWebRequest:请求已中止:无法创建SSL / TLS安全通道 - HttpWebRequest: The request was aborted: Could not create SSL/TLS secure channel 请求被中止:无法创建 SSL/TLS 安全通道 - The request was aborted: Could not create SSL/TLS secure channel HttpClientHandler / 请求被中止:无法创建 SSL/TLS 安全通道 - HttpClientHandler / The request was aborted: Could not create SSL/TLS secure channel RestSharp 请求中止 - 无法创建 SSL/TLS 安全通道 - RestSharp request aborted - could not create SSL/TLS secure channel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM