This post is for advanced learners.
HTTP header and HTTP body format with examples.
Hyper Text Transfer Protocol communication allows two types of messages to be transferred between the Client and the server, HTTP Request and the HTTP Response. The request is sent by the client/browser to the server and the response is sent by the server to the browser. Both the message have a common format, they both contain a HTTP Header and a HTTP Body.
The HTTP Header contains information about the HTTP Body and the Request/Response.
Information about the body is related to the content of the Body such as the length of the content inside the body.
The information about Request/Response is the general information about the request/response and it is not specific to the content of the body, example at what time the Request was made or the browser used to make the request.
The properties in header are specified as name-value pair which are separated from each other by a colon ‘:’ . The format is given below.
What are the types of HTTP Headers?
In HTTP 1.1, header can further divided into 3 parts.
- General Header
- Request/Response Header
- Entity Header
Nothing to do with the HTTP body’s content being transferred but it contains general information about the communication such as the date and time on which the request/response was generated. This header is common to both Request and Response. Example
Date:Tue, 17 Nov 2015 16:39:15 GMT
Request Header is present when you make a request to the server and the response header is present when the server sends a response back to the client/browser.
Request Header contains information about the request such as the URL that you have requested, the method(GET, POST, HEAD) ,the browser used to generate the request and other info. Example
User-Agent:”Mozilla/5.0 (Windows NT 10.0; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0″
The term browser is also called user-Agent. So even a simple request to a page involves sending the information about your browser and the operating system you are using. You can see from the above Header field that i am using Windows 10 and Firefox 41.0 browser.
Response Header is received by the browser from the server after the user sends a request for a particular page or resource and it contains information such as the encoding used in the content, the server software that is used on the server machine to generate the response and other information. Example
Most of the sites usually hide their server information in order to make it hard for hackers to know which software is being used on the server.
This header contains information about the actual message or the HTTP body that is being sent. Information such as content length, the language of the content, encoding, expiration date and other important stuff. Example