What happens when you view a website? (3)-HTTP Request

Louis
2 min readDec 17, 2020

After finding out where the server is, we can start to transfer messages with the server to get the content we want. In the digital world, messages are only a combination of 0s and 1s. Thus, we need to establish a standard message exchange rule, or often named protocol in the internet’s world. In the website’s region, we use HyperText Transfer Protocol(HTTP protocol) to communicate with services.

In the HTTP protocol, browsers and servers communicate with specific text messages. In one HTTP communication, a browser sends an HTTP request to the server, asking the server to provide, modify, or delete some contents. After that, the server sends an HTTP response to provide the contents asked or notifies that what’s the result of the command in the HTTP request.

A simple version of the HTTP request in our trip may like this:

GET /@gamerslouis HTTP/2
Host: medium.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0
Accept: */*

One HTTP request can be separated into three parts: the start-line, header, and message body.

The first line is the start-line which means we use the “get” method in HTTP protocol version 2 to obtain the content in “/@gamerslouis”. There are many methods defined in HTTP, such as “GET”, “POST”, “DELETE.” We often use the “GET” method to get content on a server without changing anything stored on the server. All the second line to the fifth line are the request header. The second line is used to identify what website we are surfing. In the last article, I said that one server can serve many websites. So servers use this line to provide content on the correct website. The third provides some information about what browser we are using for the server. The last line specifies what type of response content we accept. The possible options may be image, audio, webpage, and so on. Here, we accept all possible content types. In this case, the request body is empty. Sometimes, we want to carry some information within the request. Then, we will use the request body. Such as, when we register a website, the registration request will contain your username and password in the request body.

In this article, we successfully send our request to the medium server. In the next article, we will see what would be like in the response message.

--

--