table of Contents
Reserve knowledge
HTPP
Before explaining the protocol, first understand some basic computer network related knowledge
1.1 Computer network architecture
-
Define
each layer of the computer network + its set of protocols -
The role
defines the functions that the computer network can perform -
Structure Introduction
Computer network architecture is divided into 3 types:OSI
architecture,TCP
/IP
architecture, five-tier architecture
-
OSI
Architecture: clear concept & complete concept, but complex & impractical -
TCP
/IP
Architecture: Contains a series of network protocols that form the basis of the Internet, isInternet
the core protocol & is widely used in local area networks and wide area networks -
Five-tier architecture: The architecture that combines
OSI
andTCP
/IP
is designed to learn & explain the principles of computers
-
TCP
/IP
The architecture of / is introduced in detail
becauseTCP
/IP
architecture is more extensive, so the main explanation
1.2 The basic model of HTTP protocol communication
-
HTTP
The basis of protocol transmission information:TCP/IP
protocol model -
HTTP
The protocol belongs to the highest application layer
Introduction
Below, I will briefly introduce HTTP
Way of working
-
HTTP
The protocol uses a request / response working method -
The specific workflow is as follows:
Detailed HTTP message
-
HTTP
Ways to interact with data at the application layer = message -
HTTP
The message is divided into: request message & response messageUsed to send requests & respond to requests, respectively
-
Below, the two types of messages will be introduced in detail
4.1 Request message
4.1.1 Message structure
-
HTTP
The request message consists of request line, request header & request body, as shown in the figure below
-
Below, each component will be described in detail
4.1.2 Detailed structure introduction
Composition 1: request line
-
Function
declaration request method, host domain name, resource path & protocol version -
Composition of structure request line = request method + request path + protocol versionNote: Spaces cannot be saved
-
Composition Introduction
The difference between GET and PSOT methods is specifically explained here:
-
Example
design: request message adoptingGET
method,URL
address = http://www.tsinghua.edu.cn/chn/yxsz/index.htm;HTTP1.1
version
The request line is:GET /chn/yxsz/index.htm HTTP/1.1
Composition 2: Request header
-
Function: declare some information of client, server / message
-
How to use: Use "header (field name): value (value)"
-
Common request headers
1. Common headers for request and response messages
2. Common Request Header
-
Example:
(URL address: http://www.tsinghua.edu.cn/chn/yxsz/index.htm)
Host: www.tsinghua.edu.cn (indicating host domain name)
User-Agent: Mozilla / 5.0 (indicating user Agent is using Netscape browser)
Composition 3: Request body
-
Role: to store the data information to be sent to the server
Optional part, if
GET请求
no data is requested -
Usage: 3 kinds in total
So far, the request line, request header, and request body of the request message are all explained.
4.1.3 Summary
-
The summary of the request message is as follows
-
Request message example
4.2 HTTP response message
4.2.1 Message structure
-
HTTP
Response message includes: status line, response header & response body
-
Among them, the response header and response body are similar to the request header and request body of the request packet
-
The biggest difference between these two types of messages is the status line & request line
Below, each component will be described in detail
4.2.2 Detailed structure introduction
Composition 1: Status line
-
Function
statement protocol version, status code, status code description -
The composition
status line is composed of protocol version, status code & status informationAmong them, spaces cannot be saved
-
Specific introduction
-
Status line example
HTTP/1.1 202 Accepted
(accepted),HTTP/1.1 404 Not Found
(not found)
Composition 2: Response header
-
Function: declare some information of client, server / message
-
How to use: Use "header (field name): value (value)"
-
Common request headers
1. Common headers for request and response messages
2. Common Response Header
Composition 3: Response body
-
Role: store the data information that needs to be returned to the client
-
Usage: It is consistent with the request body, and is also divided into: any type of data exchange format, key-value pair form and partial form
4.2.3 Summary of response messages
4.3 Summary
Below, a brief summary of the two message structures
Additional knowledge
The following will explain some HTTP
additional knowledge:
-
HTTP1.1
WithHTTP1.0
distinction -
HTTP
WithHTTPS
distinction -
HTTP
Ways to handle long connections
5.1 Differences between HTTP1.1 and HTTP1.0
Http1.1
Compared Http1.0
with the following advantages:
-
Introduce persistent connections, that is
TCP
, multipleHTTP
requests & responses can be transmitted in the same connection -
Multiple requests & responses can be performed simultaneously and can be overlapped
-
Introduce more request headers & response headers
No fields such as those related to authentication, state management &
Cache
caching, etc.HTTP1.0
host
5.2 The difference between HTTP and HTTPS
5.3 How HTTP handles long connections