0

I have an app which will download publicly available data as a string from a website.

The below code on a WinForm app on Windows 10 works perfectly, but it doesn't work at all on Windows Server 2019.

I have tried enabling the "Allow App Through Firewall" option & have also tried allowing the program in outbound rules in the firewall, but nothing is working.

What is the issue?

Private Async Function Run_WebRequest(URL As String) As Task(Of String)
   Try
       Dim client As WebClient = New WebClient()
       ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
       client.Headers.Add("scheme", "https")
       client.Headers.Add("accept-language", "en-US, en;q=0.9, ml;q=0.8")
       Dim Response = client.DownloadString(URL)
       Return Response
   Catch ex As Exception
       Return ex.ToString
   End Try
End Function

I missed to add that this is a Virtual Private Server OS Windows Server 2019 from Contabo hosting services

Please see below screenshot of the app which is a standalone exe file with three buttons having different Webclients for testing, none of them works on

App screenshot

shab
  • 127
  • 9
  • Could you show us the stacktrace? 2. Do you need to use WebClient instead of HttpCLient? Can you use Wireshark on server to see network packets? Does the URL works in browser on that server? Is there a proxy server ? – Leszek P Oct 11 '21 at 16:07
  • Are you sure the issue is actually Firewall/network related? Have you confirmed that the application has been deployed correctly? – Hursey Oct 11 '21 at 20:22
  • @LeszekP , I am not pretty sure how i can get stacktrace while VS not installed on this server ? Have tried WebClient, HttpClient, WebRequest all off them works on Windows 10 not on this Server , yes this URL works on browser on the server. After your comment i installed Webshark and captured the traffic by running this app as well as browsers , i cant see any HTTP traffics on the log ? – shab Oct 12 '21 at 10:38
  • Why is that function `Async` when it's not? Don't ignore your compiler warnings. – GSerg Oct 12 '21 at 10:44
  • @Hursey, not sure if it is related to firewall/network but sure about that deployment is done correctly, this is standalone exe file copied over to server with all dependencies, the app works , i am able to click on the buttons but no response, after a while task gets cancelled or timeout happens, from Windows 10 it takes less than 1 second to get response so there is no doubt on the timeout – shab Oct 12 '21 at 10:46
  • @GSerg , since i am not getting any response wanted to test with other clients such as WebClient, HttpClient o WebRequest , so not to make UI frozen just gave an async task to let me click on other buttons, not sure if thats the right way of doing though !! – shab Oct 12 '21 at 10:50
  • The `Async` keyword is not "magically don't freeze the UI" and you will easily [achieve the opposite](https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html) by using it this way. That function is synchronous, please write it as such. Also please show how you call it. – GSerg Oct 12 '21 at 10:53
  • @GSerg , it is called as : `Private Async Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click txtResultRichBox.Text = Await Run_WebRequest(TextBox1.Text) End Sub` – shab Oct 12 '21 at 11:03
  • That looks fine. So it's that Webclient [throws exceptions](https://stackoverflow.com/q/15346362/11683) on non-success HTTP codes, which means there is no connectivity from your program to that URL on the server. – GSerg Oct 12 '21 at 11:09
  • @GSerg , what do you suggest to look at ?, this URL is reachable from web browsers on that server , further the firewall is completely opened for this program, is there any other area i need to look at ? – shab Oct 12 '21 at 12:14
  • 1
    Double check these facts. Also try changing `= SecurityProtocolType.Tls12` to `= ServicePointManager.SecurityProtocol Or SecurityProtocolType.Tls12`. – GSerg Oct 12 '21 at 12:50

0 Answers0