Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get description for HTTP status code

In ASP.NET you can set the Response.StatusCode to for example 404. Should the status line / description always be set? (to in this case "404 Page Not Found")

How do you get the description if you only have the code (404)? Is this somewhere in the framework or do you manually have to hardcode the descriptions?

like image 979
jaap Avatar asked Aug 22 '10 18:08

jaap


People also ask

How can I get HTTP status code?

Just use Chrome browser. Hit F12 to get developer tools and look at the network tab. Shows you all status codes, whether page was from cache etc.

What are status code 2xx 3xx 4xx 5xx in API?

2xx successful – the request was successfully received, understood, and accepted. 3xx redirection – further action needs to be taken in order to complete the request. 4xx client error – the request contains bad syntax or cannot be fulfilled. 5xx server error – the server failed to fulfil an apparently valid request.

What is Httpstatuscode OK?

OK indicates that the request succeeded and that the requested information is in the response. This is the most common status code to receive.

Who defines HTTP status codes?

An HTTP status code is a message a website's server sends to the browser to indicate whether or not that request can be fulfilled. Status codes specs are set by the W3C. Status codes are embedded in the HTTP header of a page to tell the browser the result of its request.


2 Answers

You can use the static method HttpWorkerRequest.GetStatusDescription for this.

like image 83
Ronald Wildenberg Avatar answered Sep 23 '22 09:09

Ronald Wildenberg


If you need it at the same time you're pulling Response.StatusCode, you can get the description from Response.StatusDescription.

like image 30
John Sheehan Avatar answered Sep 22 '22 09:09

John Sheehan