HTTP

Hypertext transfer protocol. It is the standard for requests and responses between clients and servers.

The HTTP request packet is sent to the server through TCP, and the server sends a response packet to the client.

Fields in request and response packets

Request format:

  • Request line Example: (GET /images/logo.gif HTTP/1.1) Request method path + Query parameters Protocol name/version
  • Request headers such as (Host: requested domain name /Ip) tell the server what I want to do and specify the content format
  • A blank line
  • Request body: For POST requests, the required parameters are not placed in the URL, but in the request body

Response format:

  • Status line Example: (HTTP/1.1 200 OK) Protocol name/version Status code Status character string
  • Response header For example, (Content-Type: text/ HTML) Indicates the format of the request header in the request packet
  • A blank line
  • Response body: Resources required by the request

The HTTP status code

The client sends a request to the server, which tells the client the status of the current request.

2XX successful response:

  • 200 The OK request succeeded
  • 206 Partial Content Server processed part of the request. For example, upload files in fragments. The server processes part of the request during the request.

3XX redirection (further client action required to complete the request)

  • 301 Moved Permanently The requested resource was Moved to a new location. For example, if the server does not have an interface for a URL request, it responds with a new address and redirects the client to the correct address
  • The 304 Not Modified client sends a GET request and requests the same content as the last time it was accessed. That is, the client resources are not modified and can still be used normally. In this case the server will return 304, telling the client to fetch the resource directly from memory

4XX Client error

  • 401 Unauthorized Requests require authentication information
  • 403 Forbidden Request Denied For example, only back-end users can access the interface. Common users cannot access the interface
  • 404 Not Found The requested content server did Not find the page

5XX Server error

  • 503 Service Unavailable The server is not ready to process the request. Probably because the server is down.

What’s new with HTTP2.0

  • Based on binary streams. A TCP connection is divided into streams. Each stream can transmit several messages, and each message consists of several binary frames.
  • Multiplexing. A TCP connection can handle multiple requests.
  • Server push. The client sends a request for HTML, and the server sends the HTML to the client along with the resources needed in the HTML
  • Compressing Http headers
  • Requests can be prioritized