c# - 请求中止:无法在主机上创建 SSL/TLS 安全通道,本地运行正常
问题描述
作为更大应用程序的一部分,我需要从我的 asp.net 应用程序(我使用 C# 和 Framework 4.6.1)中读取网页。我的本地代码运行良好,但是当我将其上传到我的主机(Aruba 共享主机)并尝试阅读https://forumcommunity.net/时,我收到错误“请求中止:无法创建 SSL/TLS 安全通道“..而其他网站被正确阅读(例如谷歌,youtube等)。也许是我的主机的问题.. 但我不知道从哪里开始解决问题.. 在此先感谢您的帮助。
string Uri = TextBoxLink.Text;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Uri);
request.Method = "get";
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resSteam = response.GetResponseStream();
StreamReader sr = new StreamReader(resSteam);
TextBoxResult.Text = sr.ReadToEnd();
}
catch (Exception ex)
{
LabelError.Text = ex.Message;
}
解决方案
推荐阅读
- asp.net-web-api2 - [Authorize] 属性如何使用 owin 令牌进行授权?
- swift - 是否可以使用 NativeScript 显示用 SwiftUI 编写的视图
- asp.net-core-2.0 - 在 Visual Studio 中自动生成 API 控制器
- ruby-on-rails - Rails 4 使用 send_data 方法下载的 excel 文件出现格式错误
- javascript - 如何使用离线 Jquery?
- jsf - 未填充 selectOneMenu
- java - 提取文件中的值并将其转换为字符串以获得更多功能
- python - 如何让 pip 代理与公司证书链一起使用?
- php - 如何在多张图片上传中同时使用 id 和 name?
- node.js - 如何在 VS Code 上为 ejs 文件获得正确的语法高亮显示?