WebResponse() StatusCode returns "OK" but not 200?

I know that they are the same thing, but why does "OK" return instead of "200"? I also want to make sure that I am returning all possible status codes (i.e. 404), if applicable. If I don't get a 200, I get a long exception, which is useful, but I also need a "quick look".

Am I missing something?
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(i.ToString());
request.KeepAlive = false;
 
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
 
Response.Write(response.StatusCode);
response.Close();
}
catch (WebException err)
{
Response.Write("Error: " + err);
}

Open in new window

LVL 3
xizwyckAsked:
Who is Participating?
 
gregoryyoungConnect With a Mentor Commented:
you can cast the status code to an integer which is the number http://msdn.microsoft.com/en-us/library/system.net.httpstatuscode.aspx contains a list of all of the codes
0
 
gregoryyoungCommented:
Its the difference between the status code and the status description?

http://msdn.microsoft.com/en-us/library/system.web.httpresponse.statuscode.aspx

btw: 200 is not the only valid "success" in the HTTP protocol. See the other 2xx in http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Cheers,

Greg

0
 
xizwyckAuthor Commented:
I tried using StatusDescription. Both return "OK". And I know that 200 isn't the only one, that's the point, I want the actual number, not OK.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
gregoryyoungCommented:
Status Code returns an enum  ... StatusDescription returns you what the actual status was.

Cheers,

Greg
0
 
xizwyckAuthor Commented:
Right... so why are they both the same?
0
 
apeterConnect With a Mentor Commented:
The StatusCode parameter is a number that indicates the status of the HTTP response. The expected values for status are defined in the HttpStatusCode class.
HttpStatusCodeStatusCode.OK is equivalent to HTTP status 200. OK indicates that the request succeeded and that the requested information is in the response. This is the most common status code to receive.

0
 
xizwyckAuthor Commented:
I see what you mean. It occurred to me a while ago and I found a list but you have been very helpful, thank you.
0
 
xizwyckAuthor Commented:
Thank you. I have gregoryyoung the larger split since he posted earlier. Thanks again.
0
All Courses

From novice to tech pro — start learning today.