https, 在WIN7 下如果服务器断没有启用tls1.0, 那webClient 请求就会失败,
问题解决方案 https://stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel
try
{
ServicePointManager.Expect100Continue = true;
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
string testUrl = "https://www.baidu.com/";
testUrl = "https://www.thoughtco.com/swimming-4132739";//不用上面代码就会失败,error:The request was aborted: Could not create SSL/TLS secure channel.
WebClient wc = new WebClient();
string s = wc.DownloadString(testUrl);
richTextBox1.Text = s;
}
catch(Exception ex) {
richTextBox1.Text = "error:" + ex.Message;
}
-----------------------------------------------------------------------------------------------------
The solution to this, in .NET 4.5 is
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
If you don’t have .NET 4.5 then use
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
-------------------------------------------------------------------------------------------------------
很遗憾的是这个在XP下还是不行。
。