Home  >  Article  >  What is http a protocol mainly used for?

What is http a protocol mainly used for?

青灯夜游
青灯夜游Original
2020-10-23 15:20:1520931browse

http is a protocol mainly used to transfer data between browsers and servers. The HTTP protocol is the most widely used network transmission protocol on the Internet. All WWW files must comply with this standard; it is based on the TCP/IP communication protocol to transmit data (HTML files, image files, query results, etc.).

What is http a protocol mainly used for?

http (HyperText Transfer Protocol) is a simple request-response protocol that usually runs on top of TCP. It specifies what kind of messages the client may send to the server and what kind of response it gets. The headers of request and response messages are given in ASCII code; the message content has a MIME-like format. This simple model was instrumental in the early success of the Web because it made development and deployment so straightforward.

At the beginning of HTTP's birth, it was mainly used for content acquisition on the WEB side. At that time, the content was not as rich as it is now, the layout was not as exquisite, and there were almost no user interaction scenarios. For this simple scenario of obtaining web content, HTTP performs reasonably well. But with the development of the Internet and the birth of WEB2.0, more content began to be displayed (more picture files), layout became more exquisite (more CSS), and more complex interactions were introduced (more jS). The total amount of data loaded and the number of requests when a user opens the homepage of a website are also increasing.

The size of the home page of most portal websites today will exceed 2M, and the number of requests can be as high as 100. Another widespread application is in mobile Internet client APPs. APPs of different natures use HTTP in very different ways. For e-commerce apps, there may be more than 10 requests to load the homepage. For IMs such as WeChat, HTTP requests may be limited to downloading voice and picture files, and the frequency of requests is not high.

Working Principle

HTTP is based on the client/server model and is connection-oriented. Typical HTTP transaction processing has the following process:

(1) The client establishes a connection with the server;

(2) The client makes a request to the server;

(3) The server Accept the request and return the corresponding file as a response according to the request;

(4) The client and server close the connection.

The HTTP connection between the client and the server is a one-time connection. It limits each connection to process only one request. When the server returns the response to this request, it immediately closes the connection and restarts the next request. establish connection. This one-time connection mainly takes into account that the WWW server is oriented to tens of thousands of users on the Internet and can only provide a limited number of connections. Therefore, the server will not leave a connection in a waiting state. Timely release of the connection can greatly improve the server's performance. effectiveness.

HTTP is a stateless protocol, that is, the server does not retain any state when transacting with the client. This greatly reduces the memory load on the server, thereby maintaining a faster response speed. HTTP is an object-oriented protocol. Allows the transfer of data objects of any type. It identifies the content and size of transmitted data through data type and length, and allows compressed transmission of data. When the user defines a hypertext link in an HTML document, the browser will establish a connection with the specified server through the TCP/IP protocol.

Technically speaking, the client opens a socket on a specific TCP port (the port number is usually 80). If the server has been listening for connections on this well-known port, the connection will be established. The client then sends a request block containing the request method over the connection.

The HTTP specification defines 9 request methods. Each request method specifies a different information exchange method between the client and the server. Commonly used request methods are GET and POST. The server will complete the corresponding operations according to the client's request, return it to the client in the form of a response block, and finally close the connection.

The above is the detailed content of What is http a protocol mainly used for?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:what does youtube mean?Next article:what does youtube mean?