Hi all,
I have an external application that calls WebClient to download a file from our server. It runs fine without any proxy server involved. However, once there is a proxy server layer, it throws a 407 proxy authentication required error.
My question is that since I do not know whether the users are going to download a file thru a proxy, is there a way in C# to specify a general way of coding to handle proxy and non-proxy users?
Here is my code snippet:
try
{
WebClient wc = new WebClient();
// Call Web Client to download file
wc.DownloadFile(dataSourceUrl, localSaveFilePath);
}
Catch (WebException we)
{
// Report exception
}
I have looked at the web and seen people saying that I could use
WebClient wc, wc.proxy = WebProxy.GetDefaultProxy();
wc.Proxy.Credentials = CredentialCache.DefaultCredentials;
However GetDefaultProxy is a deprecated method and what can I use under a .NET framework 2.0 environment. Furthermore, I have read a article somewhere saying that I don't need to define the proxy settings since it's automatically inherited from IE. That's what I have and it doesn't work at my customer's computer.
Any help is appreciated and thanks very very much.
Thomas.