0

I used to be able to read a text file located on our public web server, into a string variable. Something has changed on the web server and now my function does not work anymore. The text file is still there and can be opened using a web browser but I cannot read it from my VB.net application

Here is the link to a sample text file: https://www.mgfx.co.za/license.txt

        Dim http As New Net.Http.HttpClient        
    Dim strWebString As String = Await http.GetStringAsync(New Uri("https://www.mgfx.co.za/license.txt"))

This does not work anymore and throws an error about authentication. "IOException: Authentication failed because the remote party has closed the transport stream."

I can only imagine that our hosting provider has implemented some sort of new security measures which now block calls from my app.

Can anyone help here or know why this is the case?

Raider_007
  • 29
  • 5
  • 1
    May want to check that you're using TLS 1.2, not the default 1.1...a lot of web servers are requiring that now and I've been dealing with programs erroring because of that all year – soohoonigan Nov 27 '18 at 19:58
  • Just add this line before sending the request for the first time: `ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls`. – 41686d6564 stands w. Palestine Nov 27 '18 at 20:00
  • It's really strange but the code works for me pretty well: `Using client As New HttpClient : Dim x = Await client.GetStringAsync(New Uri("https://www.mgfx.co.za/license.txt")) : End Using` – JohnyL Nov 27 '18 at 20:16
  • Thanks guys! The TLS 1.2 setting seems to have solved it. – Raider_007 Nov 27 '18 at 20:27
  • @JohnyL Maybe, you have something like this: `` or this: `` in your `app.config` file. There's also a registry value that can set this protocol as the default. Some applications, it happens, do this behind your back. Some developers think it's all OK, then they deploy and... – Jimi Nov 27 '18 at 20:50

1 Answers1

0

Adding this to my code fixed the issue.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls
Raider_007
  • 29
  • 5