首页 > 解决方案 > 请求中止:无法在主机上创建 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;
    }

标签: c#asp.netsecurityssltls1.2

解决方案


推荐阅读