c# - 请求被中止:无法创建 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
解决方案
您是否使用 SSL 证书,因为您需要使用一个。看看这个帖子,这能解决你的问题吗? 电报机器人 SSL 错误
推荐阅读
- php - 如何在 laravel 刀片中使用会话数据作为变量?
- hugo - 如何让 Hugo 渲染块引用?
- php - 在 Laravel 6 中显示数据库中的图像时检索路径错误
- python - 图表是空的..Python 2.7
- c# - 在 c# windows 应用程序中关闭子窗体时如何刷新另一个窗体?
- python - macosX下的python:验证:映射文件没有cdhash,完全无符号?代码必须至少是临时签名的
- javascript - 计算并定义具有特定 ID 前缀的输入数量
- spring - 如何使用@scheduled 知道所有线程在spring boot @async 中完成
- android - 防止前台服务进入睡眠模式
- angular - 以角度绑定json数组值