首页 > 解决方案 > 请求被中止:无法创建 SSL/TLS 安全通道。在本地工作但不住在

问题描述

我正在与电报机器人进行简单的集成以将消息发送到频道。下面的代码在本地工作,但是当我现场尝试时,它给了我这个错误。

代码

        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
        string urlString = $"https://api.telegram.org/bot{apilToken}/sendMessage?chat_id={destID}&text={text}";
        WebClient webclient = new WebClient();
        webclient.DownloadString(urlString);

错误

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

[WebException: The request was aborted: Could not create SSL/TLS secure channel.]
   System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) +298
   System.Net.WebClient.DownloadString(Uri address) +106
   System.Net.WebClient.DownloadString(String address) +32

标签: c#ssl

解决方案


您是否使用 SSL 证书,因为您需要使用一个。看看这个帖子,这能解决你的问题吗? 电报机器人 SSL 错误


推荐阅读