title: 502 Bad Gateway on POST/PUT Web API Calls from ASP.NET Core MVC
body: <p>I'm getting strange errors in ASP.NET Core when calling Web API that I have created for the application. GET requests go through fine and return all of the data that they should, but my POST/PUT commands all return a 502, specifically from the MVC application. I can call the API's from Postman and get a proper response and the object is created in the database. </p>
  
  <blockquote>
    <p>502 - Web server received an invalid response while acting as a
    gateway or proxy server. There is a problem with the page you are
    looking for, and it cannot be displayed. When the Web server (while
    acting as a gateway or proxy) contacted the upstream content server,
    it received an invalid response from the content server.</p>
  </blockquote>
  
  <p>I am impersonating an Integrated Windows Login with the following code for all web requests to the API:</p>
  
  <pre><code>async Task Action()
  {
      response = await _service.CreateIncident(model);
  }
  
  await WindowsIdentity.RunImpersonated(identity.AccessToken, Action);
  </code></pre>
  
  <p>CreateIncident(model):</p>
  
  <pre><code>using (var client = new HttpClient(new HttpClientHandler { UseDefaultCredentials = true }))
          {
              var newIncident = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
              var response = await client.PostAsync(hostUri, newIncident);
              return response;
          }
  </code></pre>
  
  <p>There is also one GET Request that I make through Ajax to get an incremented ID to display to the user before they create their new Incident that returns a 502 Bad Gateway as well. Is this an IIS Setting that is incorrect?</p>