1

I'm using the webclient class in .net and I went to download a site.

Dim oWebClient As New WebClient()
Dim oDownloadedPage As String = oWebClient.DownloadString(<site>)

It tossed an authentication error after a little searching it turned out that the site I was trying to download must of disabled TLS1.0

So I changed the ServicePointManger to this

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or 
   SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls

I got the same error.. So I decided to change it to this..

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or 
   SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12

See what I did there? I switched the order and then it worked.

Can someone explain to me what the difference is in the ordering? And why does it matters? I'm wondering if I go to download a TLS 1.0 site, if it will fail.

Henry
  • 2,953
  • 2
  • 21
  • 34

1 Answers1

1
System.Net.ServicePointManager.SecurityProtocol = DirectCast(3072, System.Net.SecurityProtocolType) 'TLS 1.2
Dim inStream As StreamReader
Dim webRequest As WebRequest
Dim webresponse As WebResponse
Dim cResult As String = ""
dim cURL as String="https://your.page.com"
webRequest = WebRequest.Create(cURL)
webresponse = webRequest.GetResponse()
inStream = New StreamReader(webresponse.GetResponseStream())
cResult = inStream.ReadToEnd()

this worked form me!!!

  • 1
    While this might answer the question, you should [edit] your answer to include an explanation of *how* this code block answers the question. This makes your answer much more useful to those who come across the same issue later on. – Hoppeduppeanut Jun 15 '20 at 23:48