DEV Community

Panda Quests
Panda Quests

Posted on

How does HTTP work?

When browsing the internet you are using the HTTP/HTTPS protocol. Whenever you are clicking a button, calling an address in the browser, download a file on the internet, you are making an HTTP request. As simple as they may seem, there are process behind the curtain that make it all work. Have you ever wondered how it works behind the curtain? In this article I’ll explain to you how HTTP works.

HTTP is a so called request response protocol. Meaning the client sends the request and the Server replies with a response. Request and response are both carefully formatted messages that the other can understand. Both messages are different message types. They are exchanged in a single HTTP transaction. These messages are in ASCII text and formatted according to the HTTP standard so client and server know how to interpret the content correctly.

Any application that is able to open a network connection to a server machine and is able send data over the network can make an HTTP request. Even you can try this. Just type in manually the HTTP request by using Telnet from the command line. Heads up: A normal telnet session connects over port 23. As it was mentioned before, in order to connect to a server via HTTP we have to use port 80.

In the following example we will use Telnet in order to

  • connect to a server
  • make an HTTP request
  • receive an HTTP response

telnet www.google.com 80

This command tells the computer to connect to a server with the host name “www.google.com” on port 80. After the connection is established you can write the HTTP request message:

GET / HTTP/1.1

The “GET” part tells the server we want to retrieve a resource.
The “/” tells the server that the resource we want to retrieve is located at the root resource of the home page.
“HTTP/1.1” tells the server we are using the HTTP 1.1 protocol to speak to him.

Next you type this line:

host: www.google.com

That line specifies the requested resource on the server, because one server could host multiple websites.

After you type in this and pressed ENTER twice, you should see the HTTP response. The response is plain and simple HTML code. If the code would send to a browser then he would take the code render it into a website.

Do you have any questions? Please leave a comment and I’ll get back to you as soon as possible.

This article was first published in my blog
https://link.medium.com/1hsIYpyZ2jb

Top comments (0)