HTTP knowledge point summary (Python), knowledge point python
An http request consists of three parts: request line, message header, and request body.
HTTP (Hypertext Transfer Protocol) is a stateless, application-layer protocol based on request and response modes. It is often based on TCP connections, HTTP1.1 provides a persistent connection mechanism. Most Web development applications are Web applications built on the HTTP protocol.
1. What are common HTTP methods?
GET: Used to request access to resources recognized by the URI (Uniform Resource Identifier). parameters can be passed to the server through the URL.
POST: used to transmit information to the server. The main function is similar to the GET method, but the POST method is generally recommended.
PUT: transmission file. The message body contains the file content and is saved to the corresponding URI location.
HEAD: obtains the packet header, which is similar to the GET method but does not return the packet body. It is generally used to verify whether the URI is valid.
DELETE: DELETE a file. Unlike the PUT method, DELETE the file at the URI location.
OPTIONS: query the HTTP methods supported by the corresponding URI.
2. Differences between GET and POST Methods
Difference 1:
Get focuses on obtaining resources from the server, and post focuses on sending data to the server;
Difference 2:
Get transmits data through a URL request, in the form of field (field) = value, placed in the URL, and connected with "", multiple request data are connected, for example, https: // 127.0.0.1/Test/login. actionname = admin & password = admin. This process is visible to users;
The post transmission data uses the Http post mechanism to store the fields and corresponding values in the Request Entity and send them to the server. This process is invisible to users;
Difference 3:
Get transfers a small amount of data, because it is subject to URL length restrictions, but it is more efficient;
Post can transmit a large amount of data, so only the Post method can be used to upload files;
Difference 4:
Get is insecure because the URL is visible and may leak private information, such as passwords;
Post is more secure than get;
Difference 5:
The get method can only support ASCII characters. Chinese characters transmitted to the server may be garbled.
Post supports the standard character set and can correctly pass Chinese characters.
3. HTTP request message and Response Message format
The Request Message consists of three parts:
A. Request Line: contains the request method, URI, and HTTP Version Information.
B. Request Header field
C. Request content entity
The Response Message consists of three parts:
A. Status line: the reason phrase that contains the HTTP Version, status code, and status code
B. response header field
C. Response content entity
4. Common HTTP Status Codes
Returned status
1xx: indicates that the request has been received and continues to be processed.
2xx: Success-indicates that the request has been successfully received, understood, and accepted
3xx: Redirection-further operations are required to complete the request
4xx: client error-the request has a syntax error or the request cannot be implemented
5xx: Server Error -- the server fails to fulfill the valid request
200: the request is processed normally.
204: the request is accepted but no resources are available to return
206: the client is only a part of the requested resource. The server only executes the GET Method for some requested resources. The corresponding message uses the resource within the specified Range through Content-Range.
301: Permanent redirection
302: Temporary redirection
303: similar to status code 302, it only requires the client to redirect to another URI through the GET method when requesting a URI.
304: when a request with a condition is sent, it is returned if the condition is not met and has nothing to do with redirection.
307: Temporary redirection, similar to 302, only mandatory POST Method
400: The request message syntax is incorrect and cannot be recognized by the server
401: authentication required for requests
403: the requested resource is not allowed to be accessed
404: the server cannot find the corresponding resource
500: Internal Server Error
503: the server is busy
5. New Features of HTTP1.1
A. Default persistent connection saves traffic. As long as no TCP connection is explicitly closed at any end of the client server, the connection is maintained and multiple HTTP requests can be sent.
B. pipelines. The client can send multiple HTTP requests at the same time without waiting for a response one by one.
C. resumable upload Principle
6. Common HTTP header fields
A. General header field (the header field used in both request packets and response packets)
Date: the time when the message was created.
Connection: Connection Management
Cache-Control: Cache Control
Transfer-Encoding: The Transmission Encoding Method of the message body.
B. Request Header field (the header field used by the request message)
Host: the server where the requested resource is located
Accept: the media type that can be processed.
Accept-Charset: acceptable Character Set
Accept-Encoding: acceptable Content Encoding
Accept-Language: acceptable Natural Language
C. Response Header field (the header field used in the Response Message)
Accept-Ranges: acceptable byte range
Location: The URI to which the client is redirected.
Server: HTTP Server installation information
D. object header field (the header field used in the Entity part of the request message and Response Message)
Allow: HTTP methods supported by resources
Content-Type: Type of the entity main class
Content-Encoding: Encoding method applicable to entity entities
Content-Language: the natural Language of the entity.
Content-Length: the number of bytes of the Object Body.
Content-Range: the location Range of the Object Body. It is generally used to send partial requests.
7. disadvantages of HTTP and HTTPS
A. The communication uses plain text not encrypted, and the content may be eavesdropped.
B. the identity of the communications party is not verified and may be disguised.
C. The message integrity cannot be verified and may be tampered.
HTTPS is HTTP plus encryption (generally SSL Secure Communication Line) + Authentication + Integrity Protection
8. HTTP Optimization
Use Server Load balancer to optimize and accelerate HTTP applications
Use HTTP Cache to optimize websites