title: Authentication error when requests go through proxy
body: <p>I have the following code that makes a web request through a proxy server. I sniffed the network traffic with wireshark on the server and found that I get the following error when the request is made:</p>
  
  <p>Your credentials could not be authenticated: "Credentials are missing.". You will not be permitted access until your credentials can be verified.\n</p>
  
  <p>The authentication should be running through NTLM.</p>
  
  <p>Can anyone help please?</p>
  
  <pre><code>    //... CALL THE CODE
      string url = String.Format("http://currencyconverter.kowabunga.net/converter.asmx/GetCultureInfo?Currency={0}", CurrencyTo.Text);
      returnValue = GetResponseValue(url);
      //...
  
      private static string GetResponseValue(string url)
      {
          WebRequest request = InitialiseWebRequest(url);
  
          WebResponse response = request.GetResponse();
          System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream());
  
          XDocument xmlDoc = new XDocument();
          xmlDoc = XDocument.Parse(sr.ReadToEnd());
  
          string returnValue = xmlDoc.Root.Value;
          return returnValue;
      }
  
      private static WebRequest InitialiseWebRequest(string url)
      {
          WebRequest request = WebRequest.Create(url);
  
          if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["proxyLogin"]))
          {
              string proxyUrl = ConfigurationSettings.AppSettings["proxyUrl"];
  
              if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["proxyPort"]))
              {
                  proxyUrl += ":" + ConfigurationSettings.AppSettings["proxyPort"];
              }
  
              WebProxy proxy = new WebProxy(proxyUrl);
  
              // Create a NetworkCredential object and associate it with the Proxy property of request object.
              proxy.Credentials = new NetworkCredential(ConfigurationSettings.AppSettings["proxyLogin"], ConfigurationSettings.AppSettings["proxyPassword"]);
  
              NetworkCredential networkCredential = new NetworkCredential(ConfigurationSettings.AppSettings["proxyLogin"], ConfigurationSettings.AppSettings["proxyPassword"]);
  
              CredentialCache credentialCache = new CredentialCache();
  
              credentialCache.Add(new Uri(url), "NTML", networkCredential);
  
              request.Credentials = credentialCache;
              request.Proxy = proxy;
  
              return request;
          }
  
          return request;
      }
  </code></pre>