I am testing out the httpClient sendAsync method. Synchrnous call it works fine. But, when I try to do asynchronous http
requests, the task terminated before I process the message. Any body encountered with this issue?
This synchronous call works
HttpRequestMessage httprequest = new HttpRequestMessage(httpmethod, "http://www.google.ca");
var result = _httpClient.SendAsync(httprequest, HttpCompletionOption.ResponseContentRead, cancellationToken);
HttpResponseMessage response = result.Result;
But the Asynchrnous call doesn’t work. The thread dies when I try to parse the response.
HttpRequestMessage httprequest = new HttpRequestMessage(httpmethod, "http://www.google.ca");
var result = await _httpClient.SendAsync(httprequest, HttpCompletionOption.ResponseContentRead, cancellationToken);
HttpResponseMessage response = result;
any help is appreciated.
If you are using VS11 Beta, then make sure your unit test returns
Task, notvoid.If you’re using VS2010 or VS11 Dev Preview, then you can use my Async Unit Tests project.
Full details are on my blog, but it boils down to this:
asyncwill return when it has to asynchronously wait.