• 欢迎访问一起聊聊,欢迎加入一起聊聊 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏一起聊聊吧

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

程序教程 admin 2020-08-07 17:07:47 2128次 0条 未收录

访问https网站时出现错误:请求被中止: 未能创建 SSL/TLS 安全通道。
请求被中止: 未能创建 SSL/TLS 安全通道。
解决方法:在创建HttpWebRequest之前创建ServicePointManager
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    public string BrowseRequest(string url)
    {
        string result = "";
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "GET";
        request.Timeout = 5000;
        request.ContentType = "application/x-www-form-urlencoded";
        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
            {
                result = sr.ReadToEnd();
            }
        }
        return result;
    }

一起聊聊 , 版权所有丨如未注明 , 均为原创
转载请注明原文链接:请求被中止: 未能创建 SSL/TLS 安全通道。
喜欢 (1)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址