I have a file on a secured site I would like to download using a WPF application. The file is a tab delimited text file at a URL of the form https://my.server.com/test/my%5Ffile.txt. Here is the code that I have so far:
Uri uri = new Uri("https://my.server.com/test/my_file.txt");
System.Net.WebClient client = new System.Net.WebClient();
try
{
client.DownloadFile(uri, "my_file.txt");
}
finally
{
client.Dispose();
}
However, this throws a System.Net.WebException with the message "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."
Attempting to reach the file in by web browser first brings up the warning that the certificate issued by the server is not trusted, but in most modern browsers you can step through and reach the file successfully.