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 (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:
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)
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:
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)
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:
An internal error occurred on the server. This may be because of an application error or configuration problem
The service is currently unavailable, perhaps because of essential maintenance or overloading
Question: Can you work out why the following images are not displayed correctly?
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.
The URL for this image incorrectly uses port 81 and the error ERROR_INTERNET_CANNOT_CONNECT is returned by IE.
The TCP connection was closed before the server could return its response, causing IE to return the error ERROR_INTERNET_CONNECTION_RESET
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.
No access to this image is allowed. The server returned 403 Forbidden
The server returned 501 Internet Server Error
Using HttpWatch with Example 3
To view the errors that occur when downloading the images:
- Open HttpWatch by right clicking on the web page and selecting HttpWatch from the context menu
- Click on Record to start logging requests in HttpWatch
- Click on the Refresh this page button
- 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".
- 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
- More detail on each image can be viewed by selecting the Summary tab