HTTP Status Codes and Errors

3. HTTP Status Codes and Errors

An HTTP request can fail because of a network error or because of problems encountered while the request is executing on the web server.

3.1 Network Errors

If a network error occurs while transmitting a request message, error information is available from the underlying network component; e.g. Windows Sockets or WinInet. Monitoring tools like HttpWatch can display error codes for situations such as:

The host name could not be converted into an IP address, perhaps because an invalid host name was used or because no DNS lookup service is available.

The browser could not connect to the web server. This may happen if the web server is not running or is listening on the wrong port.

The network connection may be broken while transmitting the request message, perhaps because a physical network connection has been interrupted, e.g. a network cable has been unplugged.

3.2 Status Codes

HTTP status codes are returned by web servers to describe if and how a request was processed. The codes are grouped by the first digit:

1xx – Informational

Any code starting with ‘1’ is an intermediate response and indicates that the server has received the request but has not finished processing it. For example, IIS initially replies with 100 Continue when it receives a POST request and then with 200 OK once it has been processed

2xx – Successful

These codes are used when a request has been successfully processed. For example, the value 200 is used when the requested resource is being returned to the HTTP client in the body of the response message.

3xx – Redirection

Codes starting with a ‘3’ indicate that the request was processed, but the browser should get the resource from another location. Some examples are:

302

The requested resource has been temporarily moved and the browser should issue a request to the URL supplied in the Location response header.

304

The requested resource has not been modified and the browser should read from its local cache instead. The Content-Length header will be zero or absent because content is never returned with a 304 response

301

This indicates that the content now resides permanently at the location specified by the Location header and future requests should be directed to this location.

302

Same as 301, except that the new location is temporary and future requests should still be sent to the original location. Another feature of this status code is that if the original request was a POST the client will change to using a GET when it re-issues the request (See below for more details).

303

This status code was intended to be the only status code that caused a POST to be converted to a GET. However, most browsers treat a 302 like a 303.

304

Used in response to an If-Modified header to redirect a request to the browser’s local cache.

305

A 305 response is used to specify that a request must be resubmitted through the HTTP proxy in theLocation header

4xx – Client Error

The server returns these codes when they is a problem with the client’s request. Here are some examples:

401

Anonymous clients are not authorized to view the requested content and must provide authentication information in the WWW-Authenticate request header.

404

The requested resource does not exist on the server

5xx – Server Error

A status code starting with the digit 5 indicates that an error occurred on the server while processing the request. For example:

500

An internal error occurred on the server. This may be because of an application error or configuration problem

503

The service is currently unavailable, perhaps because of essential maintenance or overloading