ASP.NET 解决 请求被中止: 未能创建 SSL/TLS 安全通道。(.NET 4.0)

using (WebClient wc = new WebClient())
            {
                ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;  
                
                var data = wc.DownloadData(url);
                string html = Encoding.GetEncoding("UTF-8").GetString(data);

            }


因为ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12  只有升级到.NET 4.5才可以用,所以在.NET4. 0只要在抓取前面加 ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072 就可以啦


你可能感兴趣的:(ASP.NET,MVC)