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.
- A status line.
- A series of HTTP headers, or header fields.
- A message body, which is usually needed.
Status line
- The HTTP version number, showing the HTTP specification to which the server has tried to make the message comply.
- A status code, which is a three-digit number indicating the result of the request.
- A reason phrase, also known as status text, which is human-readable text that summarizes the meaning of the status code.
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
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.