Ok in my code I create an HttpRequest object. I then use the Request.GetResponse() to get a response. Now sometimes the response does not return a status code of 200, and this causes an exception to be thrown. I would like to be able to get the status code and status description members of the response object, however, it looks like the response object is NULL.
I dont understand why microsoft decided to throw an exception and keep response NULL, instead of allowing us to see what the status code and status description were. What can I do to get around this? I know I can parse out the status code in the exception message, but I can't do this with the status description (Microsoft reports the default status description associated with the status code; however there are custom status descriptions used here that I want to parse). Here is my code:
WebResponse response;
try
{
response = request.GetResponse();
//process the response.........
}
catch(Exception e)
{
//here i would like to get response.StatusCode
//and response.StatusDescription
//however response is NULL at this point
}
I dont understand why microsoft decided to throw an exception and keep response NULL, instead of allowing us to see what the status code and status description were. What can I do to get around this? I know I can parse out the status code in the exception message, but I can't do this with the status description (Microsoft reports the default status description associated with the status code; however there are custom status descriptions used here that I want to parse). Here is my code:
WebResponse response;
try
{
response = request.GetResponse();
//process the response.........
}
catch(Exception e)
{
//here i would like to get response.StatusCode
//and response.StatusDescription
//however response is NULL at this point
}