?
Solved

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

Posted on 2008-10-15
8
Medium Priority
?
7,980 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

 
LVL 3

Author Comment

by:xizwyck
ID: 22724652
Right... so why are they both the same?
0
 
LVL 25

Assisted Solution

by:apeter
apeter earned 150 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 225 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

752 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