0

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!

Adi Lester
  • 24,731
  • 12
  • 95
  • 110
JavaScript Developer
  • 3,968
  • 11
  • 41
  • 46

1 Answers1

0

I'd expect EndGetResponse to throw the same exception which would be thrown directly if you'd called the synchronous GetResponse method.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194