Why "(502) Bad Gateway" error happen?
<p>Windows 7 SP1.<br>
Domain network.<br>
.NET Framework 4.6.1. </p>

<p>All my Internet browsers have configured proxy settings for Internet connections (it works fine). </p>

<p>I need to download file from Internet. I configure <code>WebClient</code> 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):</p>

<pre><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();
}
</code></pre>

<p>What I did wrong?</p>

<p><a href="https://i.stack.imgur.com/Av9D9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Av9D9.png" alt="enter image description here"></a></p>