Home  >  Article  >  Operation and Maintenance  >  Detailed explanation of HTTP protocol

Detailed explanation of HTTP protocol

青灯夜游
青灯夜游forward
2019-11-29 10:08:442783browse

Detailed explanation of HTTP protocol

1. Introduction to HTTP protocol

http (Hypertext Transfer) protocol is the most widely used one on the Internet. A network protocol, mainly used for Web services, which is implemented by computers processing text information in the format of HTML (Hypertext Markup Language).

2. Http protocol version:

0.9 version: only supports html pages (has been eliminated);
Version 1.0:
(1) Introducing the MIME (Multipurpose Internet Mail Extensions) mechanism, which allows you to send multimedia messages;
(2) Introducing the keep-alive mechanism to support the persistent link function (but this The principle of keep-alive is formed by adding a certain field to the header, and this function is not supported natively);
(3) Introducing the function of supporting cached pages;
Version 1.1: An upgrade to version 1.0, supporting more Request connection mode, optimize persistent links, and optimize page caching;
Version 2.0: Provides http semantic optimized transmission and adds a spdy technology. Spdy technology: a technology introduced by Google that can accelerate http data interaction, especially the use of SSL acceleration mechanism; it is commonly known as https protocol;

is currently the most commonly used on the Internet. HTTP2.0 version.

3. Common web page types:

Static pages:

Common suffixes The name is:

  • Text: html, htm, txt, css, doc;

  • Picture: gif, jpg, png;

  • Video: mp4, flv;

Request process, as shown in the picture:

Detailed explanation of HTTP protocol

socket is an abstraction layer between the application layer and the transport layer. The essence of socket is a programming interface (API). It abstracts the complex operations of the TCP/IP layer into several simple interfaces for the application layer to call to realize the process on the network. China Communications. TCP/IP is just a protocol stack, which must be implemented specifically and also provide an external operation interface (API). This is the Socket interface. Through Socket, we can use the TCP/IP protocol.

①The Web client registers the socket with the kernel;

②The client sends a data request to the Web server through the browser;

③The Web server receives the client's request information;

④If the resource requested by the client is local to the server, the http service will apply to the system kernel for a call;

⑤The kernel calls the data in the local disk and sends the data to the server;

⑥http sends the resource requested by the user through the response message, and finally responds to the client;

Features: It is pre-written by the developer and stored in the current file system. The response speed is fast and the page maintenance is troublesome. , poor data interactivity, easy to be included by search engines;

Dynamic pages:
Common suffixes are: php, jsp, asp, net...

Request process:

Detailed explanation of HTTP protocol

The difference from static pages is that if the user requests dynamic content, then the http server will call the back-end interpreter, and the back-end interpreter will obtain the data from the disk. , run through the interpreter to generate files in html format. Then it is constructed into a response message and finally responds to the client's request.

Features: The web server itself does not support the processing of dynamic pages, and a special interpreter is required to complete it. The page data is changeable, the page maintenance is relatively simple, the response speed is slow, the data is interactive, and when the page is accessed, Contains special symbols? , %, & (special symbols) cannot be included by search engines;

Pseudo-static page: Disguise dynamic pages as static pages and be included by search engines, consuming hardware resources;

4. HTTP protocol message:

request Message: client→server

The client sends a request to the server, and different websites are used to request different resources (html documents)

Request message format:

Detailed explanation of HTTP protocol

Request line: Used to identify the resource requested by the client, what is the request method, requested resource, and requested protocol, they are directly separated by "space";

Request header : The function is to inform the server through the relevant content requested by the client (there can be more than one header)

Blank line: There will be a blank line after the request header, by sending a carriage return characters and newline characters, used to notify the server that the request header information will no longer appear in the following content;

Requesting entity:What is the specific content of the requested page

Response Message (response message): server → client

The server responds to the client's request;

Response message format:

Detailed explanation of HTTP protocol

Starting line: The version of the http protocol used in the response, the response status code, and the brief information of the status code;

Response header: Similar to the request message, there are usually several header fields after the start line. Each header field contains a name and a value, separated by colons, and can contain one or more.

Blank line: After the last response header information is a blank line. By sending carriage return and line feed characters, the client is notified that there is no header information under the blank line;

Response entity: Really access the content contained in the page;

5, HTTP request method

In the HTTP communication process , each HTTP request message will contain an HTTP request method, which is used to inform the client to request the server to perform certain specific operations.

Common HTTP request methods: GET, POST, HEAD

Detailed explanation of HTTP protocol

##6, HTTP status code

Status code outline:

Detailed explanation of HTTP protocol

Common status code description:

Detailed explanation of HTTP protocol

If the above status code If no corresponding information is found, please refer to

HTTP status code details

7. HTTP things

includes An HTTP request and the response to the corresponding request are called an HTTP transaction. It can also be understood that an HTTP transaction is a complete process of HTTP request and HTTP response.

HTTP protocol opens and closes a new connection by default, so it is quite time-consuming and bandwidth-intensive. Due to the slow start feature of TCP, the performance of each new connection itself will be reduced. , so the upper limit on the number of parallel connections that can be opened is limited. Therefore, using the persistent connection mode is better than not using the persistent connection by default. Its advantage is that the time consumed in the process of requesting and tcp disconnection will be reduced.

8. HTTP resource

The resource is through the HTTP protocol that allows users to send messages to the server through the browser or user agent based on the http protocol. Request and obtain content, such as html documents, pictures, etc.

Resource type: It is marked by MIME;

Format: main tag and this tag;

Common MIME types:

Detailed explanation of HTTP protocol

9. URL introduction

URL, the full name is Uniform Resource Location, Chinese translation is Uniform Resource Locator, also known as web page address (website). Like a house number, it is the standard unique address of a resource on the Internet. In layman's terms, URL is a string used to describe information resources on the Internet, and is mainly used in various www client and server programs. URLs can use a unified format to describe various information resources, including files, server addresses and directories, etc. Strictly speaking, each URL is a URI, which identifies an Internet resource and specifies a method to operate on it or obtain the resource.

The format of URL consists of the following three parts:

The first part is the protocol, for example: http.

The second part is the host resource server IP address or domain name (port number), for example: www.kgc.cn

The third part is the specific address of the host resource, such as directory and file name etc., for example: teacher/index.html

The first part and the second part are separated by the "://" symbol, and the second part and the third part are separated by the "/" symbol. The first and second parts are indispensable, the third part can be omitted

10. URI introduction##URI (Uniform Resource Identifier) It is called the same resource identifier in Chinese. It is a string used to identify the name of an Internet resource. This identification allows users to interact with the resource through a specific protocol. Every resource available on the Web, including HTML documents, images, video clips, programs, etc., is located by a universal resource identifier. So we can use URI to identify the name of each resource;

11. How does http connect multiple requests concurrentlyBecause http defaults to Working under the blocking model, by default only one request is received at a time. After the request is processed, the next request is received, so it can only be received one by one.

So we want to respond to user requests concurrently and require a multi-process model. The web server itself will generate multiple child processes to respond to user requests. That is to say, when a user request is sent to the web server, the main web process will not directly respond to the user request, but will generate a child process to respond to the user request. In this way, when the child process After establishing a connection with this user. The main process of the Web will wait for another user's request. When the second user request comes, a child process will be generated to respond to the second user request. And so on. So every user request is handled by a child process.

CDN computer room: The CDN computer room is used to store static resources

If a user wants to request a data, then it will send a request to the web server, and then respond to the client , then if hundreds of millions of people around the world request the back-end server, then the back-end server will not be able to handle it, and the access speed will be very slow. This will be the birth of such a thing as CDN, cdn The content of the page will be stored. When the client accesses a page, it will first visit the CDN computer room. If the CDN computer room does not have a cache, it will return to the source, and then cache a copy for the CDN and present it to the client. The next time it visits There is no need to go back to the source, it can be accessed directly on the CDN, which reduces the pressure on the back-end server.

Related article tutorials: web security tutorial

The above is the detailed content of Detailed explanation of HTTP protocol. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:51cto.com. If there is any infringement, please contact admin@php.cn delete