HTTP defines
HTTP (HyperText Transfer Protocol) is the most widely used network Transfer Protocol on the Internet, and all WWW files must comply with this standard.
HTTP is a TCP/ IP-based communication protocol to transfer data (HTML files, image files, query results, etc.). HTTP is at the application layer and the default HTTP port number is 80
How HTTP works
The HTTP protocol works on a client-server architecture. As the HTTP client, the browser sends all requests to the HTTP server, namely the WEB server, through the URL.
The request message
An HTTP request packet consists of four parts: request line, header, blank line, and request data. For example:
POST /user HTTP/1.1 // Request line Host: www.user.com Content-type: application/x-www-form-urlencoded Connection: Keep-alive user-agent: Mozilla/5.0Copy the code
The illustration
1.1 request line
The request line consists of three parts: request method, request URL (excluding domain name), and HTTP protocol version
1.1.1 Request method
1) GET
The length of the passed parameter is limited because the passed parameter is represented directly in the address bar, and specific browsers and servers have restrictions on the length of the URL.
Therefore, GET is not suitable for transferring private data or large amounts of data.
The average HTTP request is mostly a GET.
2) POST
POST encapsulates the data to be transferred in HTTP request data in the form of names and values. It can transfer a large amount of data without limitation and will not be displayed in the URL.
The form is submitted using POST.
3) the HEAD
HEAD is similar to GET, but when a server receives a HEAD request, it returns only the response header, not the response content. So, if you only need to view the status of a page, HEAD is more efficient because it saves time transferring the content of the page.
4) the DELETE
Delete a resource.
5) OPTIONS
Used to get the method supported by the current URL. If the request is successful, the HTTP header contains a header named “Allow” with the value of the supported method, such as “GET, POST”.
6) PUT
To store a resource in a specified location.
In essence, PUT and POST are very similar in that they send data to the server, but there is one important difference. PUT usually specifies where resources should be stored. POST does not.
For information on the difference between POST and PUT and the idempotency of request methods, see article 7 Request Methods and idempotency of HTTP
7) TRACE
The command output displays the requests received by the server for testing or diagnosis.
8) CONNECT
The CONNECT method is reserved for HTTP/1.1 and enables the connection to be piped to a proxy server. Typically used for communication between SSL encrypted server links and unencrypted HTTP proxy servers.
HTTP version 1) HTTP/1.0
HTTP/1.0 supports GET, POST, and HEAD HTTP request methods.
2) HTTP / 1.1
HTTP/1.1 is the version currently in use. This version uses persistent connections by default and works well with proxy servers. Multiple requests can also be piped simultaneously to reduce line load and increase transmission speed.
HTTP/1.1 added five HTTP request methods: OPTIONS, PUT, DELETE, TRACE, and CONNECT.
1.2 Request Headers
The request header consists of keyword/value pairs, one per line
- User-agent: indicates the type of the browser that generates the request
- Accept: Indicates the data type that the client wants to Accept. For example, Accept: Text/XML (application/json) indicates that the client wants to receive XML (JSON)
- Content-type: indicates the data Type of entity data sent by the sender. For example, content-type: text/ HTML (application/json) indicates that the Type sent is HTML.
- Host: specifies the requested Host name. Multiple domain names can reside at the same IP address, that is, a virtual Host
The response message
The STRUCTURE of an HTTP response packet is similar to that of a request packet and consists of four parts:
< status-line > // Status line < headers > // Message header < blank line > // Response-body > // response bodyCopy the code
Status code
- 1XX: message indicating that the server has received the browser request and continues processing
- 2XX: Indicates that the browser request is successfully received and processed
- 3XX: redirect, indicating that further processing is required
- 4XX The client request error indicates that the client request error occurs
- 5XX A server error occurs. The server fails to correctly process client requests
Common status code explanation:
- 200 OK: Indicates that the client request is successfully received and the response data is sent to the client
- 302 Found: Redirect, the new URL will be returned in Response, and the browser will automatically send the request to the new URL.
- 304 Not Modified: Indicates that the information has been cached and can still be used
- 403 Forbidden: The server receives client requests but refuses to provide services for the client
- 404 Not Found: Resource requested by client does Not exist
- 500 Internet Server Error: An unexpected Error occurs on the Server
HTTP packet structure and content
expand
How can cookies be carried across domains
Cookie information is not carried by default when configuring cross-domain. WithCredentials = true on the cookie client and access-Control-allow-credentials: true on the server
What is a fat URL
Fat urls: urls that contain user status information are called fat urls
The cache
The next article focuses on caching
Will:
- What are the contents of HTTP packets?
- What are the important parts of the HTTP protocol header, the HTTP status code?
- HTTP Status code What are the status codes?
- What is strong caching? What is weak caching?
- What is the browser’s live caching mechanism? How do I set up HTTP caching?
- What HTTP methods do you know? What’s the difference between POST and PUT?
- How to compress data (ZLIB), Gzip? What is the scope of compression, and does the request header compress?
- Cross-domain, why does JS restrict cross-domain? How are cross-domains allowed?
Basis:
- What are the reasons that affect the speed of the network?
- What is the main cause of network packet loss?
- What are the five layers of reference models for network architecture? What is the relationship between them?
- We often hear about packets, segments (groups), datagrams, frames, and packets. What are the relationships between them?
- Ajax can send HTTP requests. How does it relate to HTTP?
- What problems did HTTP1.0 to HTTP1.1 solve?
- What are the features of HTTP2?
- Why does HTTP1.1 have queue head blocking? SSL and TLS relationship? How to implement THE HTTPS protocol?
Reference documentation
www.cnblogs.com/myseries/p/… www.jianshu.com/p/e544b7a76…