title: The remote server returned an error: (407) Proxy Authentication Required
body: <p>I referred several websites, which had answer for this question
  "The remote server returned an error: (407) Proxy Authentication Required." ,but none were helpful. 
  I wrote a sample code to check the proxy authentication in office. The code throws exception.</p>
  
  <p>My requirement:- Verify what the website returns. Outside office, the code works fine, but in office it throws an exception due to proxy.
  When I hardcode the credentials using new NetworkCredential, it works fine. </p>
  
  <pre><code>int ResponseCode;
  string url = "http://www.msftncsi.com/ncsi.txt";
  WebRequest request = WebRequest.Create(url);
  
  request.Credentials = CredentialCache.DefaultCredentials;
  using (WebResponse response = request.GetResponse())
   {
  
     Stream dataStream = response.GetResponseStream();
     StreamReader reader = new StreamReader(dataStream);
     responseFromServer = reader.ReadToEnd();
     ResponseCode = (int)((HttpWebResponse)response).StatusCode;
     reader.Close();
  }
  </code></pre>
  
  <p>I do not want to Hardcode. I referred the solution in <a href="http://social.msdn.microsoft.com/Forums/is/csharpgeneral/thread/c06d3032-dceb-4a1a-bb6a-778fd13a938a" rel="nofollow">http://social.msdn.microsoft.com/Forums/is/csharpgeneral/thread/c06d3032-dceb-4a1a-bb6a-778fd13a938a</a>, but even that didnt help.
  What am I missing?</p>