title: Windows Authentication Web API Unauthorized - Multiple Servers
body: <p><strong>The Scenario</strong></p>
  
  <p>I have two applications running on separate servers, within the same internal network. </p>
  
  <p>Server 1 contains a WebAPI MVC Project.</p>
  
  <p>Server 2 contains a MVC Web Application which calls the API on server 1.</p>
  
  <p>Both Applications work using Windows Authentication.</p>
  
  <p>The code works fine when I'm running them locally, both through IIS and running through Visual Studio.</p>
  
  <p>When running on the server I get the following error:</p>
  
  <blockquote>
    <p>The remote server returned an error: (401) Unauthorized.</p>
  </blockquote>
  
  <p>Below is the request from Fiddler.</p>
  
  <pre><code>GET http://server1/..../..../GetTest HTTP/1.1
  Host: server 1
  Connection: keep-alive
  Cache-Control: max-age=0
  Authorization: Negotiate YIIHIgYGKwYBBQUCoIIHFjCCBxK.....
  Upgrade-Insecure-Requests: 1
  User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
  Accept:     text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  Accept-Encoding: gzip, deflate, sdch
  Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
  Cookie: ASP.NET_SessionId=gffyzdgub41op0diygy5lyv2
  </code></pre>
  
  <p>Below is the API request code</p>
  
  <pre><code>public string GetTest()
  {
  
      string sURL = "http://server2/.../api/test?value=JERONIMO";
      WebRequest wrGETURL = WebRequest.Create(sURL);
  
      wrGETURL.Credentials = CredentialCache.DefaultCredentials;
      var result = "";
      using (Stream objStream = wrGETURL.GetResponse().GetResponseStream()) {
          using(StreamReader objReader = new StreamReader(objStream)) {
  
              string sLine = "";
              int i = 0;
  
              while (sLine != null) {
                  i++;
                  sLine = objReader.ReadLine();
                  if (sLine != null) result += sLine;
              }
          }
      }
  
      return result;
   }
  </code></pre>
  
  <p>Thanks for the help.</p>