Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the relevant knowledge points of HTTP protocol

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the relevant knowledge points of HTTP protocol". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian to study and learn "what are the relevant knowledge points of HTTP protocol" together.

introduction

HTTP is an acronym for Hyper Text Transfer Protocol, a transfer protocol used to transfer hypertext from a Web server to a local browser. HTTP is a TCP/IP-based communication protocol to transfer data (HTML files, image files, query results, etc.). It does not involve packet transmission, but mainly specifies the communication format between the client and the server. By default, port 80 is used.

I. Characteristics of HTTP

Simple and fast: When a customer requests a service from a server, it only needs to transmit the request method and path. Common request methods are GET, HEAD, PUT, Delete, POST. Each method specifies a different type of client-server contact. Because HTTP protocol is simple, the program size of HTTP server is small, so the communication speed is very fast.

Flexibility: HTTP allows transmission of any type of data object.

No connection: The meaning of no connection is to limit each connection to only one request. After the server processes the client's request and receives the client's response, the connection is disconnected. In this way, transmission time can be saved.

Stateless: The HTTP protocol is stateless, and the HTTP protocol itself does not save the communication state between the request and the response. There is no dependency between any two requests. Intuitively speaking, each request is independent and has no direct connection with the previous request and the subsequent request. The protocol itself does not retain information about all previous request or response messages. This is because HTTP is designed to be so simple in order to process a large number of transactions faster and ensure the scalability of the protocol.

II. HTTP Message

Http message consists of request message and response message. The request message consists of four parts: request line, request header, blank line and request body. The response message consists of status line, response header, blank line and response body. Next, we will describe in detail the various parts of the request message and their functions.

1. Request line

Used to describe the type of request, the resource to be accessed, and the HTTP version used.

POST /chapter17/user.html HTTP/1.1

POST stands for request method,/chapter17/user. html stands for URI, HTTP/1.1 stands for protocol and protocol version. The most popular version is Http1.1. You can also learn about 2.0: HTTP 2.0 Protocol Interview Questions that Make Interviewers Tremble.

2. Request header

It consists of keyword/value pairs, one pair per line. Keyword and value are separated by colon ":".

The request header informs the server that there is information about the client request. It contains a lot of useful information about the client environment and the request body. For example:

Host: indicates the host name, virtual host.

Connection: HTTP/1.1 added, using keepalive, that is, persistent connection, a connection can make multiple requests.

User-Agent: requester, compatibility, and customization requirements.

3. Blank lines

*** A request header is followed by a blank line, which is very important, indicating that the request header has ended, followed by the request body.

4. Request body

Data that can carry multiple request parameters.

name=tom&password=1234&realName=tomson

The above code carries three request parameters: name, password, and realName.

HTTP request method

GET: Requests the specified page information and returns the entity body.

HEAD: Similar to a get request, except that the response returned has no specific content, which is used to get the header.

POST: Submit data to a specified resource for processing (such as submitting a form or uploading a file). The data is contained in the request body.

PUT: Data transferred from the client to the server in place of the contents of the specified document.

Delete: Requests the server to delete the specified page.

Difference between GET and POST

GET is harmless when the browser rolls back, while POST submits the request again.

GET requests are actively cached by browsers, whereas POST is not, unless manually set.

GET request parameters are kept intact in the browser history, while POST parameters are not kept.

GET requests have length limits on the parameters passed in the URL, whereas POST has no limits.

GET parameters are passed through the URL and POST is placed in the Request body.

V. HTTP status code

The status code consists of three digits, *** digits define the category of the response, and there are five categories:

1xx: Indication message-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: Redirect--Further actions must be taken to complete the request.

4xx: Client error--The request has syntax errors or the request cannot be fulfilled.

5xx: Server-side error-The server failed to fulfill a valid request.

For example, we usually have two kinds of error status codes:

403 Forbidden 404 Not Found 404 Not Found //The requested resource does not exist. For example, the wrong URL was entered.

Read more about this article "Two interesting pictures to help you understand HTTP status codes"

VI. Persistent connections

Why do I need a persistent connection?

In the original version of HTTP, TCP connections were disconnected for every HTTP communication. In the case of communications at that time, because they were all text transmissions with very small capacity, even this was not a big problem. However, with the popularity of HTTP, documents containing a large number of images have increased. For example, when using a browser to view an HTML page containing multiple images, the request to access the HTML page resource will also be sent to the other resources contained in the HTML page. Therefore, each request causes unnecessary TCP connections to be established and disconnected, increasing the overhead of traffic.

2. Characteristics of persistent connections

To solve the TCP connection problem described above, HTTP/1.1 and a part of HTTP/1.0 came up with the method of HTTP Persistent Connections (also known as HTTP keep-alive or HTTP connection reuse). Persistent connections are characterized by TCP connection states that remain as long as either end does not explicitly propose to disconnect.

The advantage of persistent connections is that they reduce the overhead caused by repeated TCP connections and reduce the load on the server side. In addition, reducing overhead allows HTTP requests and responses to end earlier, resulting in faster Web page display.

In HTTP/1.1, all connections were persistent by default, but not standardized in HTTP/1.0. Although some servers implement persistent connections through non-standard means, the server side may not be able to support persistent connections. There is no doubt that in addition to the server side, the client side also needs to support persistent connections.

VII. Pipeline

Persistent connections make it possible for most requests to be sent in a pipelining fashion. After sending a previous request, wait and receive a response before sending the next request. Pipelining allows you to send the next request without waiting for a response.

This allows multiple requests to be sent in parallel at the same time, rather than waiting for responses one after another. In layman's terms, requests are packaged once and responses are packaged once. Pipelining is premised on persistent connections.

If you are requesting an HTML Web page with 10 images, using persistent connections will make the request complete faster than connecting one image at a time. Pipelining is faster than persistent connections. The higher the number of requests, the more significant the time difference. The client needs to request these ten resources. Previously, within the same TCP connection, request A was sent first, then the server responded, and then request B was sent, and so on. The pipeline mechanism allowed the browser to make these ten requests simultaneously, but the server still responded to request A first, and then responded to request B after completion.

Thus, in the case of persistent connections, the delivery of messages over a connection is similar to:

Request 1 -> Response 1 -> Request 2 -> Response 2 -> Request 3 -> Response 3

Pipelined routing becomes something like this:

Request 1 -> Request 2 -> Request 3 -> Response 1 -> Response 2 -> Response 3

Thank you for reading, the above is the content of "what are the relevant knowledge points of HTTP protocol", after learning this article, I believe that everyone has a deeper understanding of what are the relevant knowledge points of HTTP protocol, and the specific use situation needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report