Smallest/simplest code to save a web page from a https URL in C# with .NET <=4.8?

50 views Asked by At

With http, it's very trivial:

WebClient client = new WebClient();
string webPageText = client.DownloadString(webPage);

Sadly, this doesn't work with https. What's the smallest amount of code that will?

Using .NET 4. I have a feeling this answer using HttpClient would work, but it requires a later .NET version (maybe 6.0) and it has async overhead/baggage apparently.

1

There are 1 answers

0
Serg On BEST ANSWER

I can say for sure that this code works well with https, at least on .net framework 4.7.2+. For older versions of .net there may be a problem with support for the up-to-date cryptography methods.

If you have control over the server you are trying to communicate with, and it is mandatory for you to use the old .net framework, then you can try to configure the server to enable some deprecated things (TLS 1.0, 1.1, etc). NOTE: Strongly NOT recommended, as it may be insecure.