title: The remote server returned error: (407) Proxy Authentication Required
body: <p>I use this code with .NET 3.5 and receive error "The remote server returned an error: (407) Proxy Authentication Required."</p>
  
  <pre><code>using (WebClient client = new WebClient())
  {
      WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
  
      try
      {
          string webPageStr = client.DownloadString(URL);
          Console.WriteLine("OK");
      }
      catch (Exception ex)
      {
          Console.WriteLine("FAIL");
          Console.WriteLine(ex.Message);
      }
  }
  </code></pre>
  
  <p>However, this code works smoothly with .NET 4.0 as this line is sufficient to pass the proxy authentication while it is not for .NET 3.5.</p>
  
  <pre><code>WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
  </code></pre>
  
  <p>Therefore, I tried many other ways to solve this problem but none of them works:</p>
  
  <p>1) Replace CredentialCache.DefaultCredentials line with</p>
  
  <pre><code>WebRequest.DefaultWebProxy.Credentials = new NetworkCredential(user, password, domain);
  </code></pre>
  
  <p>2) Create new proxy object</p>
  
  <pre><code>IWebProxy proxy = new WebProxy(proxyUrl, port);
  proxy.Credentials = new NetworkCredential(user, pass, domain);
  client.Proxy = proxy;
  client.Credentials = new NetworkCredential(user, pass, domain);
  </code></pre>
  
  <p>3) Add this line</p>
  
  <pre><code>client.UseDefaultCredentials = true;
  </code></pre>
  
  <p>4) Use HttpWebRequest instead of WebClient and repeat every procedure above. This is sample code.</p>
  
  <pre><code>HttpWebRequest webRequest = WebRequest.Create(URL) as HttpWebRequest;
  webRequest.Proxy = WebRequest.DefaultWebProxy;
  webRequest.Credentials = new NetworkCredential(user, pass, domain);
  webRequest.Proxy.Credentials = new NetworkCredential(user, pass, domain);
  
  try
  {
      webRequest.GetResponse();
      Console.WriteLine("OK");
  }
  catch (Exception ex)
  {
      Console.WriteLine("FAIL");
      Console.WriteLine(ex.Message);
  }
  </code></pre>
  
  <p>I feel like I come to a dead end as I have to use .NET 3.5. There must be difference between these two .NET versions that I do not know. Thank you very much in advance.</p>