Windows 7 SP1.
Domain network.
.NET Framework 4.6.1.
All my Internet browsers have configured proxy settings for Internet connections (it works fine).
I need to download file from Internet. I configure WebClient
for it will read proxy settings from default Internet browser and use credential of current process and I expected these conditions are enough for successfull downloading. But I get the exception (look the comment in my code):
static void Main(string[] args) {
String file_name = Path.GetRandomFileName();
String full_path = Environment.ExpandEnvironmentVariables(
Path.Combine(@"%LocalAppData%\Temp", file_name));
using (WebClient client = new WebClient()) {
client.Credentials = CredentialCache.DefaultCredentials;
//client.Proxy = WebRequest.GetSystemWebProxy();
var proxyUri = WebRequest.GetSystemWebProxy()
.GetProxy(new Uri("https://yadi.sk/i/jPScGsw9qiSXU"));
try {
client.DownloadFile(proxyUri, full_path);
}
catch (Exception ex) {
// The remote server returned an error: (502) Bad Gateway.
Console.WriteLine(ex.Message);
}
}
Console.WriteLine("Press any key for exit.");
Console.ReadKey();
}
What I did wrong?