RANT: HttpWebRequest.GetRequest throws exception when server returns status code of 500.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone else agree with me that the WebRequest object SHOULD NOT throw
an exception when the web server returns a status code of 500? I mean, 500
is a valid response and should be expected by the caller. The
HttpWebResponse object already has a StatusProperty, why can it return a
ResponseObject with the status property of 500
(System.Net.HttpStatusCode.InternalServerError). I enjoy working with the
..net framework, and I think highly of everyone involed in its creation and
ongoing progress but I find this to be a blatanly horrible design choice.
 
Hasani said:
Does anyone else agree with me that the WebRequest object SHOULD NOT throw
an exception when the web server returns a status code of 500? I mean, 500
is a valid response and should be expected by the caller. The
HttpWebResponse object already has a StatusProperty, why can it return a
ResponseObject with the status property of 500
(System.Net.HttpStatusCode.InternalServerError). I enjoy working with the
.net framework, and I think highly of everyone involed in its creation and
ongoing progress but I find this to be a blatanly horrible design choice.

I don't agree. HttpWebRequest throws excections for all status codes
but 200 and 3xx. This is documented. You can still obtain the
Response object from the WebException.Response property.

Checking for error codes is out.

bye
Rob
 
I don't agree. HttpWebRequest throws excections for all status codes
but 200 and 3xx. This is documented. You can still obtain the
Response object from the WebException.Response property.

I can't find documentation that explicitly states that it throws on 200 and
3xx, but you are right about the properties of the WebException and this
will be good enough for my needs. Thx for helping me out.
 
Hasani said:
I can't find documentation that explicitly states that it throws on 200 and
3xx, but you are right about the properties of the WebException and this
will be good enough for my needs. Thx for helping me out.

From "about HttpWebRequest"

"The HttpWebRequest class throws a WebException when errors occur while
accessing an Internet resource. The WebException.Status property is one
of the WebExceptionStatus values that indicates the source of the error.
When WebException.Status is WebExceptionStatus.ProtocolError, the
Response property contains the HttpWebResponse received from the
Internet resource."

bye
Rob
 
Back
Top