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:

  1. 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.
  2. 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.
  3. 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 (See 6. Methods)

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. (See 7. Redirection)

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 (See 5. Caching for more detail)

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. (See 10. Authentication for more detail)

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

Example 3

Question: Can you work out why the following images are not displayed correctly?

Image A: Image A

The hostname used in the URL is missing a 'w' (i.e. ww rather than www) causing the error ERROR_INTERNET_NAME_NOT_RESOLVED to be returned by IE.

Image B: Image B

The URL for this image incorrectly uses port 81 and the error ERROR_INTERNET_CANNOT_CONNECT is returned by IE.

Image C: Image C

The TCP connection was closed before the server could return its response, causing IE to return the error ERROR_INTERNET_CONNECTION_RESET

Image D: Image D

The request was processed by the server but the server returned 404 Object Not Found because the image does not exist at the specified location.

Image E: Image E

No access to this image is allowed. The server returned 403 Forbidden

Image F: Image F

The server returned 501 Internet Server Error

Using HttpWatch with Example 3

To view the errors that occur when downloading the images:

  1. Open HttpWatch by right clicking on the web page and selecting HttpWatch from the context menu
  2. Click on Record to start logging requests in HttpWatch
  3. Click on the Refresh this page button
  4. Optional: You can add a filter to capture only the images in Example 3 by adding a URL contains condition with the value "errors/images".
  5. The images that fail to download can be found by looking at the value in the Result column. If the value is too wide for the column, a tooltip will be displayed if you hold the mouse pointer over it
  6. More detail on each image can be viewed by selecting the Summary tab
<  2. Headers4. Cookies  >

Ready to get started? TRY FOR FREE Buy Now