Why does HttpClient throw an exception when a request succeeds?

I use HttpClientin the context of a web request to send another web request as follows:

private async Task SendManagerInfoAsync(Uri baseUri, string accessToken, object obj,
    string apiPath, HttpMethod httpMethod)
{
    string authToken = await GetManagerAuthToken(baseUri, accessToken)
        .ConfigureAwait(false);

    string url = new Uri(baseUri, apiPath).AbsoluteUri;

    var request = new HttpRequestMessage(httpMethod, url)
    {
        Content = new StringContent(JsonConvert.SerializeObject(obj))
    };
    request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
    request.Headers.Add("Authorization", authToken);

    // For whatever reason, always throws a TaskCanceledException.
    var response = await m_httpClient.SendAsync(request).ConfigureAwait(false);

    response.EnsureSuccessStatusCode();
}

The request I'm tracking is HTTP PUT. For some reason, this code always issues TaskCanceledExceptionafter reaching the specified length HttpClient.Timeout, about 30 seconds. However, when I check the recipient of this request, I see that the data store is always updated with the information that I sent within one second of the original request.

I don’t understand why and how the instance HttpClientthrows an exception when the request is really successful. No cancellation token is requested. Has anyone seen this behavior before?


* Akamai, , , Akamai , .

+4
1

, HttpClient, , Chrome Postman. HttpClient Expect: 100-continue . , .

m_httpClient.DefaultRequestHeaders.ExpectContinue = false;

( , , .)


Edit: , , Akamai RFC 2616 8.2. 3, , Expect: 100-continue,

  • 100 (), ,

  • ,

, Akamai 100, , , TaskCanceledException, HttpClient.

, HttpClient.DefaultRequestHeaders.ExpectContinue true, false, .

+3

All Articles