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);
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 , .