Solved

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

Posted on 2008-10-15
8
7,129 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:xizwyck
  • 4
  • 3
8 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 22724176
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
 
LVL 3

Author Comment

by:xizwyck
ID: 22724362
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
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 22724491
Status Code returns an enum  ... StatusDescription returns you what the actual status was.

Cheers,

Greg
0
 
LVL 3

Author Comment

by:xizwyck
ID: 22724652
Right... so why are they both the same?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 25

Assisted Solution

by:apeter
apeter earned 50 total points
ID: 22725197
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
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 75 total points
ID: 22725459
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
 
LVL 3

Author Comment

by:xizwyck
ID: 22725551
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
 
LVL 3

Author Closing Comment

by:xizwyck
ID: 31506430
Thank you. I have gregoryyoung the larger split since he posted earlier. Thanks again.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now