Search code examples
.netvb.nethttpswebclientvisual-studio-2003

Downloading xml file from https url


I am having problem downloading a file from HTTPS website, and i am using vb. I have this code , its simple but the main problem is that it need to be in Visual Studio 2003. Here is the code

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim client As New WebClient
    ' Download string.
    client.DownloadFile("https://www.un.org/sc/suborg/sites/www.un.org.sc.suborg/files/consolidated.xml", "consolidated.xml")

End Sub

But after i start the project i get a message telling me that:

Additional information: The underlying connection was closed: Could not establish secure channel for SSL/TLS.

Any way to get around this secure channel? Thanks


Solution

  • I solve my problem with this line of code

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
    

    Just if someone need :)