preface
- About computer networks,
HTTP
Network communication protocols are very important in any development work - Today, I will offer one
HTTP
I hope you like it
directory
1. Stock up on knowledge
Before explaining the HTPP protocol, learn some basic computer network knowledge
1.1 Computer network architecture
-
Defines the layers of a computer network + its set of protocols
-
Function Defines the functions that the computer network can perform
-
The computer network architecture is divided into three kinds: OSI architecture, TCP/IP architecture and five layer architecture
OSI
Architecture: conceptually clear & ideologically complete, but complex & impracticalTCP
/IP
Architecture: contains a set of network protocols that form the basis of the InternetInternet
The core protocol is widely used in LAN and WAN- Five-tier architecture: Fused
OSI
与TCP
/IP
Architecture for learning & explaining computer principles
TCP
/IP
A detailed introduction to the architecture of
Due to theTCP
/IP
The architecture is more extensive, so the main explanation
1.2 Basic model of HTTP protocol communication
-
HTTP
The basis of protocol transmission:TCP/IP
Protocol model
-
HTTP belongs to the highest application layer
2. Introduction
Next, take a brief look at HTTP
3. Working mode
HTTP
Deal withRequest/ResponseThe way in which- The specific working process is as follows:
4. HTTP packet details
HTTP
Data exchange at the application layer = packetsHTTP
Are classified into request packets and response packets
When sending a request and when responding to a request
- The following describes the two types of packets in detail
4.1 Request Message
4.1.1 Message Structure
HTTP
The request message is sent byRequest line, request header & request bodyComposition, as shown below
- Each component is described in detail below
4.1.2 Structure Details
Component 1: Request line
-
Function declaration request method, host name, resource path & protocol version
-
Structure request line composition = request method + request path + protocol version
Note: Spaces cannot be omitted
- Composition is introduced
The difference between GET and PSOT methods is specified here:
- The sample
Set: The request packet is adoptedGET
Methods,URL
Address =www.tsinghua.edu.cn/chn/yxsz/in…; ,HTTP1.1
version
GET/CHN /yxsz/index.htm HTTP/1.1
Component 2: Request header
- Function: Declare some information about the client, server, or packet
- Usage: Use the “header: value” format
- Common request Headers 1. Common Headers of request and response packets
2. Common request Headers
- Example: (URL: www.tsinghua.edu.cn/chn/yxsz/in.) Host: www.tsinghua.edu.cn (indicates the Host domain name) User-agent: Mozilla/5.0 (indicates that the User Agent uses the Netscape browser)
Composition 3: Request body
-
Function: Stores data to be sent to the server
Optional parts, such as GET requests, have no request data
-
Usage: 3 kinds in total
At this point, the explanation about the request line, request header and request body of the request message is finished.
4.1.3 summary
- The following table summarizes the request message
- Sample Request message
4.2 HTTP Response Packets
4.2.1 Packet Structure
HTTP
The response message contains status line, response header and response body
- The response header and body are similar to the request header and body of the request packet
- The biggest difference between the two types of messages is the status line and the request line
Each component is described in detail below
4.2.2 Structure Details
Component 1: status line
- Description Protocol version, status code, and status code description
- composition
The status line consists of protocol version, status code and status information
Where, Spaces cannot be saved
-
Detailed introduction
-
Example status line HTTP/1.1 202 Accepted, HTTP/1.1 404 Not Found
Component 2: Response header
- Function: Declare some information about the client, server, or packet
- Usage: Use the “header: value” format
- Common request Headers 1. Common Headers of request and response packets
2. Common response headers
Component 3: response body
- Function: Stores data to be returned to the client
- Usage: consistent with the request body, also divided into: any type of data exchange format, key-value pair form and partial form
4.2.3 Summary of Response Packets
4.3 summarize
The following two message structures are briefly summarized
5. Extra knowledge
Here are some additional facts about HTTP:
HTTP1.1
与HTTP1.0
The difference betweenHTTP
与HTTPS
The difference betweenHTTP
The way to handle long connections
5.1 Differences between HTTP1.1 and HTTP1.0
Http1.1 has the following advantages over Http1.0:
- Introduce persistent connections, that is, in the same
TCP
Can transmit more than oneHTTP
Request & Response - Multiple requests & responses can occur simultaneously and overlap
- Introduce more request & response headers
For example, HTTP1.0 does not have the host field related to authentication, state management, and Cache
5.2 Differences between HTTP and HTTPS
5.3 How to Process Long Connections using HTTP
6. Summary
- This article summarizes comprehensively
HTTP
Basic knowledge of - And I’m going to continue with that
Android
Relevant knowledge in development, interested can continue to pay attention toCarson_Ho android Development Notes