HTTP Tutorial
HTTP (HyperText Transfer Protocol) is an application-layer protocol used for distributed, collaborative, hypermedia information systems.
HTTP is the foundation of data communication for the World Wide Web (WWW). It is designed to ensure communication between clients and servers and is one of the most commonly used protocols on the Internet.
HTTP is a protocol that transmits data (HTML files, image files, query results, etc.) based on the TCP/IP communication protocol.
The original purpose of designing HTTP was to provide a method for publishing and receiving HTML pages. Resources requested via HTTP or HTTPS protocols are identified by Uniform Resource Identifiers (URIs).
HTTP Request-Response
The basic working principle of HTTP is that the client (usually a web browser) sends a request to the server, and after receiving the request, the server returns the corresponding resources. These resources can be web pages, images, audio files, videos, etc.
HTTP uses a client-server model, where the client sends requests and the server returns responses.

The HTTP request-response model typically consists of the following steps:
Establish connectionA connection is established between the client and the server. In traditional HTTP, this is based on the TCP/IP protocol. More recent HTTP/2 and HTTP/3 use more advanced transport layer protocols, such as the TCP-based binary protocol (HTTP/2) or the UDP-based QUIC protocol (HTTP/3).
Send requestThe client sends a request to the server. The request contains the URL of the resource to be accessed, the request method (GET, POST, PUT, DELETE, etc.), request headers (e.g., Accept, User-Agent), and an optional request body (for POST or PUT requests).
Process requestAfter receiving the request, the server finds the corresponding resource based on the information in the request and performs the appropriate processing operations. This may involve retrieving data from a database, generating dynamic content, or simply returning static files.
Send responseThe server encapsulates the processed result in a response and sends it back to the client. The response contains a status code (to indicate the success or failure of the request), response headers (e.g., Content-Type, Content-Length), and an optional response body (e.g., HTML pages, image data).
Close connectionAfter completing the request-response cycle, the connection between the client and server can be closed, unless a persistent connection is used (such as keep-alive in HTTP/1.1).
HTTP Methods
HTTP methods specify what actions the client can perform on resources on the server.
The main HTTP methods are:
- GETGET: Requests the specified resource from the server. This is the most commonly used method for accessing pages.
- POSTPOST: Requests the server to accept and process the data in the request body, usually used for form submission.
- PUTPUT: Requests the server to store a resource and replace all content of the target resource with the content in the request body.
- DELETEDELETE: Requests the server to delete the specified resource.
- HEADHEAD: Similar to GET, but does not retrieve the content of the resource, only the response header information.
HTTP Status Codes
HTTP status codes are the server's response to client requests.
Status codes are divided into five categories:
- 1xx (Informational status codes)Indicates that the received request is being processed.
- 2xx (Successful status codes)Indicates that the request was processed successfully.
- 3xx (Redirection status codes)Further action is needed to complete the request.
- 4xx (Client error status codes)Indicates that the request contains a syntax error or cannot be fulfilled.
- 5xx (Server error status codes)The server encountered an error while processing the request.
HTTP Versions
HTTP has multiple versions. Currently, HTTP/1.1 and HTTP/2 are widely used, and HTTP/3 is being gradually promoted.
- HTTP/1.1HTTP/1.1: Supports persistent connections, allowing multiple requests/responses to be transmitted over the same TCP connection, reducing the overhead of establishing and closing connections.
- HTTP/2HTTP/2: Based on binary framing, supports multiplexing, allowing multiple independent, bidirectional exchanges to be initiated simultaneously over a single HTTP/2 connection.
- HTTP/3HTTP/3: Based on the QUIC protocol, designed to reduce network latency and improve transmission speed and security.
Security
HTTP itself is insecure because the transmitted data is not encrypted and may be eavesdropped on or tampered with. To solve this problem, HTTPS was introduced (detailed in the next chapter), which adds SSL/TLS protocols to HTTP, providing encryption and authentication for data transmission.
Other Extensions