1. The HTTP definition

HTTP Hypertext Transfer Protocol (HTTP) is an application-layer Protocol that consists of requests from clients to servers and responses from servers to clients.

2. Main features of HTTP

1. Simple and quick

Simple:

  • Each resource (image, page) passes through a fixedurlTo locate. inHTTPIn the protocol, the processing is relatively simple. When accessing resources, input corresponding information directlyurlCan.

Fast:

  • Due to theHTTPThe protocol is simple enough to makeHTTPThe server’sSmall program size, therefore,Communication is fast.

2. The flexible

HTTP allows the transfer of data objects of any type. The Type being transferred is marked by content-Type.

3. No connection

Connectionless means to limit processing to one request per connection. The server disconnects from the customer after processing the request and receiving the reply from the customer. In this way, transmission time can be saved.

4. A stateless

Stateless means that the protocol has no memory for transaction processing. Stateless means that if the previous information is needed for subsequent processing, it must be retransmitted, which can result in an increase in the amount of data transferred per connection.

For example, client and server are two different identities. At the end of the first request, it is disconnected, and at the end of the second request, the server does not remember the previous state, that is, the server cannot tell whether the client is the same person, the same identity.

On the other hand, the server responds faster when it doesn’t need the previous information.

Sometimes web sites remember our login status so they don’t need to log in, not because of the HTTP protocol, but because of other means (such as sessions).

3. Components of HTTP packets

HTTP packets include request packets and response packets.

1. Request packets

The request message consists of four parts:

  • Request line: includes request method, request URL, HTTP protocol, and version
  • Request headers: Some key-value pairs
  • Empty line: After the request header is an empty line that informs the server that there is no more request header and that the content after the empty line is the request body
  • Request body: data part,GETNo requested data,POSTThere are

A simple example:

2. Respond to the packet

The response packet consists of four parts:

  • The status line:HTTPProtocol and version, status code, and status description
  • Response headers
  • A blank line
  • Response body

A simple example: