When using the WebClient class you can check for errors and empty results by using
e.error != null
and
e.result == null
respectively. How would I handle this using the HttpWebRequest class? All examples seem to omit this yet its vital in applications.
The
HttpWebRequestuses theIAsyncResultand Begin/End pairs for an operation.You will have passed a Callback method delegate to Begin operation and then in that callback you call the End method for that operation. To catch an error that may have occured in the asynchronous part of the operation you place a try block around your call to the End method.
For example when calling
BeginGetResponseyou might pass this call back:-