title: Wep API fails to return data from HttpClient call
body: <p>I have not been able to figure out why the following issue is happening:</p>
  
  <p>I have created a simple web api controller (.Net Framework 4.6.1)</p>
  
  <pre><code>public class TestController : ApiController
  {
      // GET api/&lt;controller&gt;
      public async Task&lt;string&gt; Get()
      {
          var url = "http://api.plos.org/search?q=title:DNA";
          using (var httpClient = new HttpClient())
          {
              using (var response = await httpClient.GetAsync(url))
              {
                  using (var content = response.Content)
                  {
                      var result = await content.ReadAsStringAsync();
                      return result;
  
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>When I run the code above I get the following error after about 20 seconds.</p>
  
  <pre><code>{
      "Message": "An error has occurred.",
      "ExceptionMessage": "An error occurred while sending the request.",
      "ExceptionType": "System.Net.Http.HttpRequestException",
      "StackTrace": "   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at restapitest2.Controllers.TestController.&lt;Get&gt;d__0.MoveNext() in C:\\restapitest2\\restapitest2\\Controllers\\TestController.cs:line 19\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Threading.Tasks.TaskHelpersExtensions.&lt;CastToObject&gt;d__1`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.&lt;InvokeActionAsyncCore&gt;d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.&lt;ExecuteAsync&gt;d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.&lt;SendAsync&gt;d__15.MoveNext()",
      "InnerException": {
          "Message": "An error has occurred.",
          "ExceptionMessage": "Unable to connect to the remote server",
          "ExceptionType": "System.Net.WebException",
          "StackTrace": "   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)\r\n   at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)",
          "InnerException": {
              "Message": "An error has occurred.",
              "ExceptionMessage": "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 216.74.38.80:80",
              "ExceptionType": "System.Net.Sockets.SocketException",
              "StackTrace": "   at System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult)\r\n   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)\r\n   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket&amp; socket, IPAddress&amp; address, ConnectSocketState state, IAsyncResult asyncResult, Exception&amp; exception)"
          }
      }
  }
  </code></pre>
  
  <p>When I create a dotnet core web api controller the same code works fine.</p>
  
  <p>This is what the dot net core code looks like.</p>
  
  <pre><code>[Route("api/[controller]")]
  [ApiController]
  public class ValuesController : ControllerBase
  {
      // GET api/values
      [HttpGet]
      public async Task&lt;ActionResult&lt;string&gt;&gt; Get()
      {
          var url = "http://api.plos.org/search?q=title:DNA";
          using (var httpClient = new HttpClient())
          {
              using (var response = await httpClient.GetAsync(url))
              {
                  using (var content = response.Content)
                  {
                      var result = await content.ReadAsStringAsync();
                      return result;
  
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>What is strange is that if I use an internal URL both api solutions return data.</p>
  
  <p>Any help would be appreciated</p>