4

I am using HttpClient (System.Net.Http) to send a GET request and I occasionally get the following exception:

Unable to read data from the transport connection. The connection was closed before all data could be read. Expected 894 bytes, read 0 bytes.

The instance of HttpClient that I am using is static, as Microsoft recommends, and I set the Connection header to "keep-alive". I am setting the Authorization header per request and sending the request using the following code:

        var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _authorizationHeader);

        var response = await HttpClient.SendAsync(request);

The exception is thrown on the last line in the snippet. Can someone help me figure out what would be causing this exception to be thrown?

bgoerdt
  • 162
  • 1
  • 7
  • Try to call to the server with the same query from a browser and check if it answers. – Gusman May 05 '17 at 19:58
  • *Occasionally* is hard to find out. Is the server you are fetching from local? Might it really just sometimes be unavailable like it is the nature of the internet? Any Anti-Virus or Firewall involved? – ZoolWay May 05 '17 at 19:58
  • http://stackoverflow.com/a/5420788/2779990 – Stinky Towel May 05 '17 at 19:59

1 Answers1

0

This exception was stemming from the issue described here.

The fix is to download IIS Crypto and set the template to Best Practices (requires reboot) on all relevant servers.

bgoerdt
  • 162
  • 1
  • 7