(1.1) The browser generates HTTP messages-exploration from browser to server

This article will introduce the first thing the browser does when you enter a string from the browser or click on something-to generate an HTTP request. So we first introduce the HTTP protocol.

(1) What is the HTTP protocol

The full name of the HTTP protocol is Hyper Text Transfer Protocol . It defines the message content and steps for interaction between the client and the server . The basic idea is this:

1.1 First, the client sends a request message to the server. The request message contains three parts:

  1. Where to go : refers to the URL we entered in the address bar
  2. What to do: what we want to do, also known as a method
  3. Additional information : mainly to indicate to the server where the information comes from, what is the version of the browser, etc.

1.2 The basic format of HTTP messages

Insert picture description here

1.3 HTTP is worth noting some details

  1. Table of main methods:

Insert picture description here

○: The items defined in this version
△: It is not an informal specification, but an additional function defined in the specification
2. Status code of the response

status code meaning
1XX Inform the request processing progress and situation
2XX success
3XX Indicates that further action is required
4XX Client error
5XX Server internal error

Here is a practical example:

1. Message body: because there is no message body, there is no message body

Insert picture description here

(2) What is URL

Before introducing, I must first popularize a little knowledge:

  1. The string of characters we enter in the address bar of the browser is called URL: Uniform Resource Locator Uniform Resource Locator

  2. There are many kinds of URLs, and the different functions we want to accomplish can be divided into different characters starting with different characters. For example, "http", "https", "ftp", "file". We often say that to visit a website is to visit http or URL starting with https

  3. The www.**** that we often enter is not called a URL, but is called a domain name . The function of a domain name is to let netizens remember it better . In fact, you can access the Internet without a domain name. Resource — ip address . For example, you can access Baidu's homepage in two ways: 1. https://www.baidu.com/ 2. http://14.215.177.38/

Insert picture description here

In daily life, people often describe the address bar in the browser as a web address. This is a bit one-sided. Some students even think that the string of letters in the address bar must start with www. In fact, it is not the case, the address in the browser The valid string entered in the column is exactly URL: Uniform Resource Locator Uniform Resource Locator . You can know by the name that the URL can be uniquely identified to a resource on the network. Generally speaking, it is a string of letters beginning with http . but many people may not know is that, URL can also use other beginning of the text, such as "file:", "ftp", etc., you can try using a browser to open its own file manager, here I will use their own Make a demo

Insert picture description here

This is when I opened my D drive through a browser. You can also experiment with my format. Very interesting.

Below I use another picture to list several common URLs on the Internet:
Insert picture description here

The reason there are various URLs is that our browser does not only have the function of accessing the web server. So it needs something to judge which function should be used.

(3) Parse the URL

But when we enter a URL in the address bar, it means that we already have the resource we want to access, but the browser is only facing a string, so the browser needs to parse the URL. The URL is mentioned above . There are many formats, let's take the most common and core http as an example .

According to the above figure, we know that when using the HTTP protocol (HyperTextTransferProtocol) to access the web server, the URL includes several parts. So the browser will split the URL into the following parts.

Guess you like

Origin blog.csdn.net/qq_44823898/article/details/112721886