In my corporate environment there is a transparent proxy that requires credentials for internet access (every four hours). In my application I successfully passed credentials like this:
var client = new WebClient();
client.Credientals = new NetworkCredential("username", "password");
string result = client.DownloadString("http://...");
// this works!
However, when my intial request is to a "https://" url, there is an Exception throw: "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."
Now my current work around is to:
- catch the WebException thrown when accessing the "https://" url
- add my Credentials to a new request to an arbitrary "http://" site
- (this should "open up" the internet for a four hour window)
- go back and re-try the "https://" request
I am wondering if there is a better/cleaner way to do this?