I have the following code, where sometimes the handler I am posting to times out (I do not want to extend the default timeout value) before I get a response. When this happens an AggregateException is throw where there is one InnerExceptions:
[0] {"A task was canceled."} System.Exception {System.Threading.Tasks.TaskCanceledException}
var _httpClient = new HttpClient();
var _content = new StringContent("thecontent");
var responseMessagePost = _httpClient2.PostAsync("http://localhost:50643/handler1.ashx", _content).Result;
Is this the correct behaviour?
I was expecting the variable responseMessagePost to have a Status Code of RequestTimeout = 408. For example when I do the following an exception is not thrown and I get a Status Code of NotFound = 404. Why is the behaviour different?
var httpClient = new HttpClient();
var _content = new StringContent("thecontent");
var _responseMessagePost = httpClient.PostAsync("http://localhost:50643/handlerdoesnotexist.ashx", _content).Result;