HTTP message structure

HTTP is a stateless request/response protocol based on a client/service-side (C/S) architecture model that exchanges information over a reliable link.

An HTTP "client" is an application (a web browser or any other client) that connects to the server for the purpose of sending one or more HTTP requests to the server.

An HTTP "server" is also an application (usually a Web service, such as an Apache Web server or IIS server, etc.) that receives requests from the client and sends HTTP response data to the client.

HTTP uses uniform Resource Identifiers (URIs) to transfer data and establish connections.

Once the connection is established, the data messages are transmitted in a format similar to those used by Internet mail, RFC5322, and the multipurpose Internet Mail Extension (MIME) (RFC2045).


The client requests a message

The client sends an HTTP request to the server in four formats: request line, request header, empty line, and request data, and the following illustration shows the general format of the request message.

HTTP message structure


The server responds to the message

The HTTP response is also made up of four parts: the status line, the message header, the empty line, and the response body.

HTTP message structure



The following example is a typical example of using GET to pass data:

Client request:

GET /hello.txt HTTP/1.1User-Agent: curl/7.16.3 libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3Host: www.example.comAccept-Language: en, mi

Service-side response:

HTTP/1.1 200 OKDate: Mon, 27 Jul 2009 12:28:53 GMTServer: ApacheLast-Modified: Wed, 22 Jul 2009 19:15:56 GMTETag: "34aa387-d-1568eb00"Accept-Ranges: bytesContent-Length: 51Vary: Accept-EncodingContent-Type: text/plain

Output:

Hello World! My payload includes a trailing CRLF.