Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi,
get http a number List of HTTP status codes . what i get that number with HttpWebResponse
Posted
Comments
Stephen Hewison 16-Jun-12 4:48am    
There isn't a question here. What is the problem? Can you provide more details?
me64 16-Jun-12 4:53am    
for example:
if (HttpResponce==200)
label1.text="OK";

Which method HttpResponce can i using for this action ?

Did you try looking at the documentation[^]?
 
Share this answer
 
Comments
me64 16-Jun-12 5:21am    
in here sued StatusDescription, that give (ok, Redirect, NotFound, SeeOther, etc) , but i need to get number Http
Richard MacCutchan 16-Jun-12 5:39am    
Try the StatusDescription field. maybe that has what you want. Alternatively you may need to parse the response header yourself.
me64 16-Jun-12 17:15pm    
i do not have StauseDiscription
I should using numbers(cods) http (The link in my first post)
Richard MacCutchan 17-Jun-12 3:30am    
If you want the numbers then you need to parse the HTML document from the HttpResponse object.
I think you are almost there.

You have to use HttpWebResponse.StatusCode, which will have a value of OK, Accepted, Redirect, etc. This is an enum and if you need the numerical value, all you have to do is cast it like this:
C#
int code = (int)HttpWebResponse.StatusCode;


If HttpWebResponse.StatusCode == OK, then code == 200.

Soren Madsen
 
Share this answer
 
Comments
me64 17-Jun-12 2:53am    
With this method,I only have access to a few of these specifications,While these numbers are returned by the Http more (http://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
SoMad 17-Jun-12 3:03am    
I don't know why you say "a few" - I count around 40 different values: HttpStatusCode Enumeration
[^]

Soren Madsen
me64 17-Jun-12 4:26am    
count http is much more. please you see this link in wikipedia (http://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
I need all this codes
Is there any way?
is not predicted by ASP.NET any way?
The problem you've got is HTTP is at a lower level within the solution architecture than ASP.Net.

Hyper Text Transport Protocol - The key word is transport. The transport begins within the client internet browser and ends in your ASP.Net application.

ASP.Net is only aware of requests which make it all the way from the client, across the internet, into you hosting network, to your web server and then from your web server to the ASP.Net engine.

HTTP - 500 Internal Server Error

This is often caused by a bad configuration of IIS. If IIS is poorly configured then there's no way the request is going to get from the client to the ASP.Net engine. In which case the request life cycle won't begin, the relevant modules and handlers won't execute and your ASP.Net application including it HttpWebResponse object are going to be completely ignorant.

In IIS you can enable Failed Request Tracing. This will report any bad status codes returned by IIS even if they don't make it to the ASP.Net engine.

http://learn.iis.net/page.aspx/488/using-failed-request-tracing-rules-to-troubleshoot-application-request-routing-arr/[^]

Once you've developed an understanding of the structure of this log you could write code to automatically read the log and report bad statuses in a more convenient way.

IIS also supports a technology called ISAPI (Internet Server Application Programming Interface). ISAPI layers are lower in the solution architecture than the ASP.Net engine.

The following outlines how to write a simple ISAPI layer. It is possible that adding your own ISAPI layer would allow you to capture HTTP status codes which would be missed by the ASP.Net engine but this is not a catch all.

http://blogs.msdn.com/b/rakkimk/archive/2007/03/01/writing-a-simple-isapi-filter.aspx[^]

There are HTTP status codes for timeouts. If the timeout is caused by the clients local ISP then there's no way you're ever going to know about the request or the returned status code.

In a nutshell. You will never get all of the valid statuses listed for a HTTP request/response within the ASP.Net engine as HTTP covers area's well beyond the scope of responsibility of ASP.Net.

For this very reason, the enumerator doesn't need to contain all the HTTP status codes.
 
Share this answer
 
v2
Comments
me64 17-Jun-12 18:19pm    
Hi,
Thank you to answer
1 - Do ISAPI web address related to my system only checks or any URL on the Internet
2 - The IIS configuration web adress related to my system only checks or any URL on the Internet
3 - If there is not really a way in ASP.NET, whether by Other languages ​​such as Java script and etc in asp are capable of being used, it can be done?
4 - Whether there is another language to fully solve my problem
Stephen Hewison 18-Jun-12 1:37am    
You'll have to look up ISAPI filters in google as I don't know exactly what can be achieved with them. IIS when configured can log every request including not just the address but also the HTTP status code returned with the address. No ASP.Net really can't. Nor can any other language. You missed the point of the answer. HTTP as a protocol is bigger than the technology delivering the website. HTTP is a transport technology, ASP.Net, JSP, PHP are all web server response engines. To create an analogy, it's like asking your telephone to know why someone can't place a call to you or why they got disconnected. Personally I think your question has been well answered by all three people and you should show your gratitude by accepting the answers.
me64 18-Jun-12 10:39am    
I am grateful of your response, but not impossible in programming
In the meantime I found a site that does almost the same (http://www.pingdom.com/)
But I do not know how it works
Stephen Hewison 18-Jun-12 11:12am    
Right if you're building something like pingdom then your comments make more sense. Your problem is you're using Wikipedia as a reference which lists all those who have ever been known to override/abuse the HTTP standard such as all the HTTP status codes which form part of WebDAV. These aren't valid HTTP status codes. The enumerator in .Net return which the HttpWebRequest object is the complete list of HTTP status codes as defined by w3 (The standard owner) at the following url:
http://www.w3.org/protocols/rfc2616/rfc2616-sec6.html#sec6.1
This is not an ASP.Net question. The ASP.Net tag is not relevant.

What you're trying to do is check a remote websites availability using the System.Net namespace and the HttpWebRequest object.

Using Wikipedia as a reference of valid HTTP status codes is not a good idea. It lists every company that has ever decided to return a status code which doesn't form part of the HTTP standard.

The enumerator for status code, HttpStatusCode in the HttpWebResponse is every HTTP status code recognised by W3, the owner of the standard.

For the official list of HTTP status code. Please look here:

http://www.w3.org/protocols/rfc2616/rfc2616-sec6.html#sec6.1[^]
 
Share this answer
 
Comments
me64 18-Jun-12 17:28pm    
In the address in the introduction, there is code that I do not know what language, if you say is excellent, but I guess the CGI interface that is used only for Intranet
Stephen Hewison 19-Jun-12 14:46pm    
The address in your question is a list of all HTTP status codes ever known to be returned by any software. A lot of them are not valid HTTP status codes based on the official HTTP standard. If, based on your reference to Pingdom, your goal is to remotely check the availability of a website then the only codes you will receive are those included in the HttpStatusCode enumerator used to provide the StatusCode property in the HttpWebResponse. If instead of the enumerator value you're after the integer value of the code it's simple. (int)response.StatusCode
me64 19-Jun-12 15:59pm    
In the address(http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1) in the introduction, there is code that I do not know what language, if you say is excellent, but I guess the CGI interface that is used only for Intranet

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900