HTTP protocol, http
1 Overview
HTTP is short for Hyper Text Transfer Protocol (Hypertext Transfer Protocol). It is a Transfer Protocol used for communication between servers and local browsers. It is a TCP-based application layer Protocol.
2 features
- Simple and fast: When a customer requests a service from the server, they only need to send the request method and path.
- Flexible: HTTP allows transmission of any type of data objects.
- Stateless: The HTTP server does not save client information by default.
- Supports the B/S and C/S modes.
3. Communication Process
1) The client requests the server to establish a TCP connection;
2) After a connection is established, the client sends a request message to the server;
3) after receiving the request, the server returns the corresponding response information.
4. Request Message
A typical request message is as follows:
GET/562f25980001b1b0000000338.jpg HTTP/1.1
Host img.mukewang.com
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36
Accept image/webp, image/*, */*; q = 0.8
Referer http://www.imooc.com/
Accept-Encoding gzip, deflate, sdch
Accept-Language zh-CN, zh; q = 0.8
DividedThree parts:
- Request Line: Includes the request method, access path, and HTTP Protocol version.
- Request Header: Specify attributes.
- Subject: The body of the GET request is empty. The body of the POST request contains the form information.
ItsFormatAs follows:
5. Response Message
A typical response packet is as follows:
HTTP/1.1 200 OK
Date: Fri, 22 May 2009 06:07:21 GMT
Content-Type: text/html; charset = UTF-8
<Html>
<Head>
<Body>
<! -- Body goes here -->
</Body>
</Html>
DividedThree parts:
- Status line: contains the HTTP protocol version, status code, and status information.
- Response Header: specify some attributes.
- Response body: the text that the server returns to the client.
6. Request Method
GET |
Query data |
POST |
Submitting an object to a specified resource may result in data creation or modification on the server. |
PUT |
Create or modify specified data on the server |
DELETE |
Deletes a specified resource on the server. |
HEAD |
Sends a request similar to a GET request, but does not require the response body to be returned. It is often used for fault tracking. |
OPTIONS |
Methods supported by the requested resource are returned. |
TRACE |
Trace the proxy that passes through a resource request (this method cannot be issued by the browser) |
7 Header
7.1 Request Header
Accept |
MIME Type accepted by the client |
Accept-Encoding |
Acceptable compression formats |
Accept-langou |
Acceptable language |
Connection |
Supported keep-alive features |
Host |
Specify the requested Internet host and port number |
User-Agent |
Client operating system and browser attributes |
7.2 Response Header
Server |
Server type, operating system |
Content-Type |
Media type of the response body |
Content-Encoding |
Response compression format |
Content-Language |
Natural Language of response |
Content-Length |
Length of the response body in bytes |
Keep-Alive |
Connection retention time |
8 Status Codes
1xx: |
Information Status Code 100: the client should continue sending the request 101: notify the client to use different protocols to complete the request |
2xx |
Success status code 200: OK, normal response 201: Created, create a new object 202: Accepted. The request is processed asynchronously successfully. 204: No Content. The response object is empty. |
3xx |
Redirect status code 301: Moved Premanently, permanent redirection. The value of the Location response header is still the current URL, so the redirection is hidden. 302: Found, temporary redirection, explicit redirection. The Location response header value is a new URL. 304: Not Modified: the requested resource has Not been Modified. For example, when the local cached resource file is compared with the server, the server returns a 304 status code, telling the browser, you don't need to request this resource. You just need to use the local resource directly. |
4xx |
Client error status code 400: Bad Request, Request syntax error 401: Unauthorized. The requested resource cannot be authorized to unauthenticated users. 403: Forbidden. The requested resource is not authorized to the current user. 404: Not Found, the requested URL resource does Not exist 405: Method Not Allowed, the request Method does Not match 406: Not Acceptable, the requested media type does Not match |
5xx |
Server Error status code 500: Internal Server Error, Internal Server Error 501: Not Implemented. The server does Not support the current request. 502: Bad Gateway, which appears when the proxy server cannot reach the backend server 504: Gateway Timeout. The proxy can contact the backend server, but the backend server does not respond to the proxy server within the specified time. |
9. HTTP Version
9.1 HTTP/1.0
This is the first HTTP Protocol version that is specified in communications. It is still widely used, especially on proxy servers.
9.2 HTTP/1.1
- Persistent connections are used by default.
- Cache Processing
- MIME supported
9.3 HTTP/2
- Asynchronous connection multiplexing
- Header Compression
- Hypertext Transfer