问题
From the several topics on this I read, the vast majority are in relation to paypal, and a few other are in relation to something called ServicePointManager. This has NO RELATION to the other problems! In this case I'm just trying a basic html agility pack example with no relation to paypal or ServicePointManger:
var url = "some_url";
var web = new HtmlWeb();
var doc = web.Load(url);
And the marked line throws this error:
Unhandled Exception: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.HttpWebRequest.GetResponse()
at HtmlAgilityPack.HtmlWeb.Get(Uri uri, String method, String path, HtmlDocument doc, IWebProxy proxy, ICredentials creds) in C:\something\HtmlAgilityPack\HtmlAgilityPack.Shared\HtmlWeb.cs:line 1677
at HtmlAgilityPack.HtmlWeb.LoadUrl(Uri uri, String method, WebProxy proxy, NetworkCredential creds) in C:\Users\Jonathan\source\repos\HtmlAgilityPack\HtmlAgilityPack.Shared\HtmlWeb.cs:line 2086
at HtmlAgilityPack.HtmlWeb.Load(Uri uri, String method) in C:\something\HtmlAgilityPack\HtmlAgilityPack.Shared\HtmlWeb.cs:line 1300
at HtmlAgilityPack.HtmlWeb.Load(String url) in C:\something\HtmlAgilityPack\HtmlAgilityPack.Shared\HtmlWeb.cs:line 1197
at DownloadSeco.Program.Main(String[] args) in C:\something\Program.cs:line 16
What exactly causes this error and how does one fix it?
EDIT: I'm closing the topic apparently the issue is with my specific computer, since it works on the pc next to me.
回答1:
As I understand the Paypal have been updated TLS version. Details are here.
But .NET does not support TLS1.2 by default.
You need enable it manually.
You can do it using next code:
System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
The SecurityProtocol
it is Singleton. And you can set TLS one time in your application (not for each WebRequest). You can set TLS in your Program.cs file.
Also please review this SO topic for details.
回答2:
it worked for me, with http and also with https
来源:https://stackoverflow.com/questions/51668380/web-query-with-htmlagilitypack-throws-system-net-webexception-the-request-was-a