title: HttpClient Timeout does not appear to be working
body: <p>I have a Web API Controller that looks like this:</p>
  
  <pre><code>[Route("api/[controller]")]
  public class SlowController : Controller
  {
      [HttpPost]
      public ActionResult Post([FromBody]SlowRequest request)
      {
          var response = new SlowResponse();
          response.Id = request.Id;
          response.StartDate = DateTime.Now;
          Thread.Sleep(new TimeSpan(0, 3, 0));
          response.EndDate = DateTime.Now;
  
          return Ok(response);
      }
  }
  </code></pre>
  
  <p>Notice how there is a 3 minute sleep. This is to simulate that the post action takes a long time to return.</p>
  
  <p>And I have a client Console Application that calls this web API:</p>
  
  <pre><code>static void Main(string[] args)
  {
      try
      {
          var request = new SlowRequest();
          request.Id = Guid.NewGuid();
  
          var json = JsonConvert.SerializeObject(request);
  
          var httpClient = new HttpClient();
          httpClient.Timeout = new TimeSpan(0, 5, 0);
          httpClient.BaseAddress = new Uri("http://localhost:54316/");
          var result = httpClient.PostAsync("api/slow", new StringContent(json, Encoding.UTF8, "application/json")).Result.EnsureSuccessStatusCode();
          var apiResponse = result.Content.ReadAsStringAsync().Result;
          var response = JsonConvert.DeserializeObject&lt;SlowResponse&gt;(apiResponse);
  
          Console.WriteLine("Start Time = " + response.StartDate);
          Console.WriteLine("End Time = " + response.EndDate);
  
      }
      catch (Exception ex)
      {
          Console.WriteLine(ex.Message);
      }
  }
  </code></pre>
  
  <p>Unfortunately the client throws an exception after 2 minutes saying:</p>
  
  <blockquote>
    <p>Response status code does not indicate success: 502 (Bad Gateway).</p>
  </blockquote>
  
  <p>It seems that if the API takes more than 2 minutes to return this, exception happens. Below 2 minutes, it works just fine. This is despite the fact I have put a 5 minute timeout on the client. How do I prevent web API calls that take a long time from erroring like this?</p>