gideonisaac-4200 avatar image
0 Votes"
gideonisaac-4200 asked ·

Does ServicePointManager.SecurityProtocol handle both http and https (encrypted web pages)?

I have some code that downloads files off the net. (This is to save me time, for instance if I want to read news items from a opinion-site, I can load the links I'm interested in a user-friendly way.) Those files could be web pages, or PDFs, or text.
Suppose I have a link like: and suppose I don't know whether the link should start with "http" or "https". The way I handle it now is that I use two routines, one of which sets ServicePointManager.SecurityProtocol to TLS12, (for https) and one that sets it to 0, (for http). So if one fails, I try the other. This has the bonus that I find out which prefix is appropriate, and I also download the file.
But I did a little reading today, and in the later versions of dot net, you don't have to set the securityProtocol at all, because the default behavior is to try everything and whatever finally works gets the download done.
So I just want to be sure on this: If I delete any servicepointManager code that I hadd been using, but I put the wrong prefix on a web page, for instance http when it should be https, (or vice versa) will it be successfully downloaded? And will there be any way to know whether https was used in the successful effort, or whether http was used? If the wrong prefix means the download is not successful, I can just try both prefixes, (without using servicemanager.securityprotocol).

· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @gideonisaac-4200 ,

If I delete any servicepointManager code that...

Did you test the code for HTTP and HTTPS websites after deleting servicepointManager code?
If you want to know whether the given url is HTTP or HTTPS, you can use HttpRequest.IsSecureConnection property

1 Vote 1 ·

0 Answers