Home >>HTTP Tutorial >HTTP Messages

HTTP Messages

HTTP Messages

The HTTP Message is used to show how the client and the server share data. It is based on architecture for client-servers. An HTTP client is a programme that sends one or more HTTP request messages to a server by establishing a connection. An HTTP server is a programme which accepts connection by sending an HTTP response message to serve HTTP requests.

HTTP is based on a client-server architecture model and a stateless request / response protocol that operates via a secure TCP / IP connection to exchange messages.

An "client" of HTTP is a programme (web browser or some other client) that connects to a server for the purpose of sending one or more HTTP requests. An HTTP "server" is a programme that accepts connections to serve HTTP requests by sending HTTP response messages (usually a web server such as Apache Web Server or Internet Information Services IIS, etc.);

The Uniform Resource Identifier (URI) is used by HTTP to define a given resource and create a connection. If the connection is created, the Internet mail [RFC5322] and the Multipurpose Internet Mail Extensions (MIME) [RFC2045] will transfer HTTP messages in a format similar to the one used. These messages include client to server requests and server to client responses to which will have the following format:

HTTP-message   = <Request> |  <Response > ; HTTP/1.1 messages

HTTP requests and HTTP replies use the generic RFC 822 message format to transmit the required data. This generic message format is composed of four items below.

A Start-line
Zero or more header fields followed by CRLF
An empty line (i.e., a line with nothing preceding the CRLF) 
indicating the end of the header fields
Optionally a message-body

In the following sections, we will explain each of the entities used in an HTTP message.

Message Start-Line

A start-line will have the following generic syntax:

start-line = Request-Line | Status-Line

We will discuss Request-Line and Status-Line, when discussing respectively HTTP Request and HTTP Response messages. For now, let 's look at the start line examples in case of request and answer:

GET /hello.htm HTTP/1.1 (This is Request-Line sent by the client)

HTTP/1.1 200 OK (This is Status-Line sent by the server)

Header Fields

Fields of the HTTP header provide the necessary information about the request or response, or the object sent in the message body. There are four types of headers for HTTP messages:

General-header: These header fields are typically valid for both request messages and responses.

Request-header: These header fields are applicable to request messages only.

Response-header: These header fields are only valid for response messages.

Entity-header: These header fields describe meta information about the entity-body, or the resource I if no body is present , about the resource identified by the request.

All the headers listed above follow the same generic format, and each header field consists of a name followed by a colon (:) and the value of the field as follows:

message-header = field-name ":" [ field-value ]

Following are the examples of various header fields:

User-Agent: curl/7.16.3 libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3
Host: www.example.com
Accept-Language: en, mi
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
ETag: "34aa387-d-1568eb00"
Accept-Ranges: bytes
Content-Length: 51
Vary: Accept-Encoding
Content-Type: text/plain

Message Body

The body part of the message is optional for an HTTP message but, if available, it will be used to carry the entity-body associated with the request or answer. Usually Content-Type and Content-Length headers lines specify the nature of the associated body if entity body is associated.

A message body is the one that carries the actual HTTP request data (including the data and uploaded form data, etc.) and server HTTP response data (including files , images, etc.). The content of a message body is simple: shown below:

<html>
   <body>
   
      <h1>Hello, World!</h1>
   
   </body>
</html>

No Sidebar ads