How the network is connected (notes) Chapter 1.1 Generating HTTP request messages

This note is an excerpt from <<How is the network connected>>, I strongly recommend this book, it is very suitable for novices like me.

Chapter 1 Browser Generated Messages—Explore Inside the Browser

1.1 Generate http request message

The first step of the browser is to parse the URL. After parsing, the browser will use the HTTP protocol to access the Web server
to parse the URL. After the browser determines the Web server and file name, the following is based on this information. Generate an HTTP request message. The server will send a response message and then display it on the client

Generate the request message according to the regulations: the
first line is called the request line, as shown in the format.
Insert picture description here
Some main methods of HTTP.
Insert picture description hereOur scenario is to enter the URL in the address bar and display the web page, so the GET method should be used here, and the GET method should be used to click on the hyperlink If it is a form, the HTML source code will specify which method to use to send the request in the form's attributes, which may be GET or POSTInsert picture description here

The first line: After writing the method, add a space, and then write the URI, usually the path name of the file and program. The
HTTP version number should be added to the end of the first line. The
second line: The second line starts with the message header, Then add a blank line, and then write the data that needs to be sent. This part is called the message body, which is the body of the message.

Received response after sending request

The response and request messages are the same, the difference is only in the first line. In the response message, the content of the first line is the status code and response phrase, which are used to indicate whether the execution result of the request is successful or error. Status code and response phrase indicate The content is the same, but their uses are different.
Status code: The status code is a number, mainly used to inform the program of the result of the execution.
Corresponding phrase: the corresponding phrase is a paragraph of text to inform people of the result of the execution

Note: A request message can only write one URI. If you obtain multiple files, you must send a request for each individual file

An example is shown below to obtain a web page named sampleq.htm, which contains a picture named picture.jpg, the picture shows the message generated in the process
Insert picture description hereInsert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/mogbox/article/details/109519862