In a Blazor Server app .NET 8, I send an HTTP request to an external server, and I do not receive a response based on the specific Timeout time , based on the behavior I have seen from HttpClient
before, I expect TaskCanceledException: A task was canceled.
but nothing happens
private async Task<HttpResponseModel> PostAsync(string url, object request)
{
httpClient.Timeout = TimeSpan.FromSeconds(35);
var response = await httpClient.PostAsJsonAsync(address, request);
return await GetResponseResult(response);
}
But if I change the code above, which is a none blocking code, to a blocking code, the exception I expect will occur.
private async Task<HttpResponseModel> PostAsync(string url, object request)
{
httpClient.Timeout = TimeSpan.FromSeconds(35);
var response = httpClient.PostAsJsonAsync(address, request).Result;
return await GetResponseResult(response);
}