Communication is the core of human life, without it people will not be able to exchange ideas and interact with each other. There are set of rules followed for proper communication example harmony between listener and speaker. Similar set of rules is followed in world of Internet. In coming paragraphs we will be discussing the basic rule of internet called HTTP (Hyper text transfer protocol). Protocol is set of rules followed for specific purpose.
We will quickly test the above by using a site called httpbin.org that has number of endpoints for testing http requests/responses. We will dive more into this later.
We will be using telnet that is command that allows access to data on websites using command line.
Steps to test http request:
- Open up your terminal
- type in
telnet httpbin.org 80
- type in
GET / HTTP/1.1
- type in
HOST:httpbin.orgquickly and press ENTER key twice
- We will get the html that is located at / (root)
Terminals don’t have layout engine like browsers, so they are not capable of converting html to layout. If we enter httpbin.org we will see the html content in better layout.
We can access any endpoints available example for viewing xml we can use /xml instead of / in above command.
A basic HTTP request consists of Request line, Headers , Black line and Request Body.
As we know request can be either GET or POST.
we need to pass uri (uniform resource identifier) and HTTP version we are using as seen in below example:
Headers consist of HOST name, User Agent we are using for sending request and Accepted Language.
Next is a simple blank line and Request body which is applicable only for POST request.
In request body we pass PAYLOAD (data) along with POST request eg we need to pass some data to a particular form we can achieve that by POST request and sending data in Request Body.
Http Response also has some important parts like:
This consists of Http version, status code and status message. There are lot of status code’s like 200 which means everything is fine, 404 which means resource or page is not available example if we type in http://www.abc.com/blah and if /blah is not available then we may get 404 error message and then we server error 500 code also. You can get more details on web about all the status code.
Each status code has some message called status message associated with it example 200 has OK message while as 404 has not available message associated.
These usually consist if Server name like nginx or apache, Date on which response was received and Content type. In this case we have content of type xml while we can have html type also.
Blank Line and Response body:
After a blank line we get actual response in the form of Response Body.
Note : HTTP Protocol is Stateless. This means it does’nt remember or it does’nt keep the record of previous request.