'update old vb WebClient() code to allow TLS 1.2

I have an old xml downloader that I discovered the host has changed to require tls 1.2. Original web call code now is rejected. Program was originally an HTML scraper, later upgraded to instead download an XML file from the host. My existing xml downloader code is below (redacted for security). I've searched around but my google-fu is failing me completely.

I've gone through and reset the application's target .net framework to 4.7.2 (originally programmed in 3.5)

Imports System.IO
Imports System.Net
Imports System.Net.Mail
Imports System.Text
Imports System.Xml

...

        Dim client As New WebClient()
        Dim reqparam As New Specialized.NameValueCollection
        
        reqparam.Add("username", SWUser) 'Replace with username
        reqparam.Add("password", SWPW) 'Replace with password
        
        Dim responsebytes = client.UploadValues("https://secure.mywebsite.com/xmlFile.php", "POST", reqparam)
        responsebytes = client.UploadValues()
        Dim responsebody = (New UTF8Encoding).GetString(responsebytes)

        Dim xmlDoc As New XmlDocument
        xmlDoc.LoadXml(responsebody)        'load new response into document holder

xml is then passed off to be parsed and displayed in the gui



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source