2

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.

cybera
  • 351
  • 2
  • 17

2 Answers2

3

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.

Alexander I.
  • 2,380
  • 3
  • 17
  • 42
  • Dude did you even bother reading the post. I specifically pointed that my issues has NOTHING to do with the 2 things you mentioned i.e. paypal and service point manager. – cybera Aug 03 '18 at 08:50
  • 2
    @cybera you have a trouble with SSL connection. Your application does not support necessary SSL protocol. You need to add `SecurityProtocolType` manually and your code will work. – Alexander I. Aug 03 '18 at 08:56
  • Thanks it worked. Question is how could this have possibly been changed on my pc without me doing anything related to it. The code worked on the fly without the needed additional line of code on the next pc. – cybera Aug 03 '18 at 09:02
  • @cybera Unfortunately .NET does not use TLS1.2 by default. You need add protocol manually. You have no other way... – Alexander I. Aug 03 '18 at 09:10
  • This makes no sense. I litterally copy pasted the code I tried to run that gave the error, on another PC next to me. And the code ran smooth, where on my PC i need to add this line of code or it doesn't work. If its not added by default it should be required on the other pc as well, but it isnt. – cybera Aug 03 '18 at 09:13
  • Hmmm. Do you have equal .NET Frameworks versions on both PCs? – Alexander I. Aug 03 '18 at 09:16
  • As far as I know yes, both computers have Visual Studio 2017 installed and nothing additional has been installed on top of that. Anyways thanks a ton for you answer it solved the issue for me so I'll just continue with the work. – cybera Aug 03 '18 at 09:27
  • Thanks it worked and you saved my life :) – Alexandre Marques Oct 26 '21 at 21:57
0

it worked for me, with http and also with https

it worked for me, with http and also with https

AlexiAmni
  • 382
  • 1
  • 15
  • I restarted and tried again. I get the same error. What could be the reason that I get it and you dont? I also tried with http and https both and the result is the same for me. – cybera Aug 03 '18 at 08:48
  • maybe connection problem on that computer? have you tried to load another pages content? – AlexiAmni Aug 03 '18 at 08:50