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?

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 Commented Nov 27, 2018 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. Commented Nov 27, 2018 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 Commented Nov 27, 2018 at 20:16
  • Thanks guys! The TLS 1.2 setting seems to have solved it. Commented Nov 27, 2018 at 20:27
  • @JohnyL Maybe, you have something like this: <appSettings><add key="SecurityProtocol" value="3072" /></appSettings> or this: <add key="SecurityProtocol" value="Tls12" /> 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... Commented Nov 27, 2018 at 20:50

1 Answer 1

0

Adding this to my code fixed the issue.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.