HTTP responses

An HTTP response is made by a server to a client. The aim of the response is to provide the client with the resource it requested, or inform the client that the action it requested has been carried out; or else to inform the client that an error occurred in processing its request.

An HTTP response contains:
  1. A status line.
  2. A series of HTTP headers, or header fields.
  3. A message body, which is usually needed.
As in a request message, each HTTP header is followed by a carriage return line feed (CRLF). After the last of the HTTP headers, an additional CRLF is used (to give an empty line), and then the message body begins.

Status line

The status line is the first line in the response message. It consists of three items:
  1. The HTTP version number, showing the HTTP specification to which the server has tried to make the message comply.
  2. A status code, which is a three-digit number indicating the result of the request.
  3. A reason phrase, also known as status text, which is human-readable text that summarizes the meaning of the status code.
An example of a response line is:
HTTP/1.1 200 OK
In this example:
  • the HTTP version is HTTP/1.1
  • the status code is 200
  • the reason phrase is OK

Status codes and reason phrases explains more about these elements of the status line.

HTTP headers

The HTTP headers for a server's response contain information that a client can use to find out more about the response, and about the server that sent it. This information can assist the client with displaying the response to a user, with storing (or caching) the response for future use, and with making further requests to the server now or in the future. For example, the following series of headers tell the client when the response was sent, that it was sent by CICS®, and that it is a JPEG image:
Date: Thu, 09 Dec 2004 12:07:48 GMT
Server: IBM_CICS_Transaction_Server/3.1.0(zOS)
Content-type: image/jpg
In the case of an unsuccessful request, headers can be used to tell the client what it must do to complete its request successfully.

An empty line (that is, a CRLF alone) is placed in the response message after the series of HTTP headers, to divide the headers from the message body.

Message body

The message body of a response may be referred to for convenience as a response body.

Message bodies are used for most responses. The exceptions are where a server is responding to a client request that used the HEAD method (which asks for the headers but not the body of the response), and where a server is using certain status codes.

For a response to a successful request, the message body contains either the resource requested by the client, or some information about the status of the action requested by the client. For a response to an unsuccessful request, the message body might provide further information about the reasons for the error, or about some action the client needs to take to complete the request successfully.



dfhtl22.html | Timestamp icon Last updated: Thursday, 27 June 2019