I'm working on a Windows Phone app. Usually I would use a WebClient
however, in this specific case I've been told that I need to use a HttpWebRequest
. I can successfully fire off the request. However, occassionally it fails. Either because of a network issue or an exception thrown by the server. How do I detect an error associated with the IAsyncResult
approach? Currently, I have the following:
private void HttpWebRequest_Completed(IAsyncResult result)
{
WebRequest request = (WebRequest)(result.AsyncState);
WebResponse response = request.EndGetResponse(result);
// Detect if there was an error right here.
...
}
My code works fine unless there was an error. I'm not sure how to detect errors though. Thank you!
I'd expect EndGetResponse
to throw the same exception which would be thrown directly if you'd called the synchronous GetResponse
method.