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

Detailed introduction of HTTP

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

one。 Overview

HTTP (Hyper Text Transfer Protocol), hypertext transfer protocol, is a kind of stateless connection established on TCP. The whole workflow is basically that the client (client) sends a http request to the server, requests the required resources from the server, after receiving the request from the server, accesses the server resources according to the request, and then returns the results to the client through HTTP.

The HTTP workflow browser requests the DNS server to resolve the IP address corresponding to the domain name in the URL; after parsing the IP address, it establishes a TCP connection with the server according to the IP address and the default port 80; the browser issues a HTTP request to read the file (the file after the domain name in the URL), and the request message is sent to the server as the data of the third message of the TCP three-way handshake The server responds to the browser request and sends the corresponding html text to the browser; releases the TCP connection; the browser displays html text; http version 0.9: only html pages are supported (eliminated) Version 1.0: (1) introduce MIME (Multi-purpose Internet Mail extension) mechanism, after introducing this mechanism, you can send multimedia messages; (2) introduce keep-alive mechanism to support the function of persistent links (but this keep-alive principle is formed by adding a field in the beginning, not natively support this function); (3) introduce support for caching pages. Version 1.1: version 1.0 upgrade, support more request connections, optimize persistent links, optimize the page cache; version 2.0: provides http semantic optimized transmission, adding a spdy technology. Spdy technology: a technology introduced by google to accelerate the exchange of http data, especially using the ssl acceleration mechanism; commonly known as the https protocol; common web page types of static pages: common suffixes: text: html, htm, txt, css, doc; pictures: gif, jpg, png; video: mp4, flv

Request process

Socket is an abstract layer between the application layer and the transport layer. Socket is essentially a programming interface (API), which abstracts the complex operations of the TCP/IP layer into several simple interface provisioning layer calls to realize the process communication in the network. TCP/IP is only a protocol stack, which must be specifically implemented, while providing external operation interface (API), which is the Socket interface. Through Socket, we can use the TCP/IP protocol.

The ① Web client registers socket with the kernel

The ② client sends data requests to the Web server through the browser

The ③ Web server receives the request information from the client

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

The ⑤ kernel calls the data from the local disk and sends the data to the server.

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

Features: pre-written by developers, stored in the current file system, fast response, troublesome page maintenance, poor data interaction, easy to be included by search engines

Dynamic pages:

Common suffix names are: php, jsp, asp, net

Request process:

Different from static pages, if the user requests dynamic content, then the http server will call the back-end interpreter. The back-end interpreter will get the data on disk, and run through the interpreter to generate files in html format. Then build a response message, and finally respond to the client's request.

Features: web server itself does not support dynamic page processing, need to have a special interpreter to complete, page data is changeable, page maintenance is relatively simple, slow response, interactive data, page access contains special symbols? ,%, & (special symbol), cannot be included by search engines

Pseudo-static pages: the dynamic pages are disguised as static pages, which are included by search engines and consume hardware resources.

Http protocol message

Request Message (request message): client side → server side

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

Request message format:

Request line: used to identify the resource requested by the client, what is the request method, the requested resource, and the requested protocol, which are directly separated by "spaces" Request header: the function is to inform the server side of the blank line through the relevant content of the client request (the first part can be more than one): there will be a blank line after the request header, by sending carriage return characters and line feed characters, used to inform the server that the request header information will no longer appear in the following content Request entity: what is the content of the requested page? Response Message (response message): server-side → client server responds to client requests

Response message:

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

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

Blank line: the last response to the first message is followed by a blank line, which notifies the client that there is no header under the blank line by sending carriage return and newline characters.

Response entity: actually access the content contained in the page

HTTP request method

In the process of HTTP communication, each HTTP request message contains a HTTP request method, which is used to tell the client to request to the server to perform some specific operations.

Common HTTP request methods: GET, POST, HEAD

HTTP status code

II. How HTTP works

The HTTP protocol defines how the Web client requests Web pages from the Web server and how the server delivers the Web pages to the client. The HTTP protocol adopts the request / response model. The client sends a request message to the server, which contains the request method, URL, protocol version, request header and request data. The server responds with a status line, including the version of the protocol, success or error code, server information, response header and response data

Steps for HTTP request / response:

Client connects to Web server-> sends Http request-> server accepts request and returns HTTP response-> release connection TCP connection-> client browser parses HTML content

1. The client connects to the Web server

A HTTP client, usually a browser, establishes a TCP socket connection to the HTTP port of the Web server (default is 80). For example, http://www.baidu.com

2. Send HTTP request

Through the TCP socket, the client sends a text request message to the Web server. A request message consists of four parts: the request line, the request header, the blank line and the request data.

3. The server accepts the request and returns a HTTP response

The Web server parses the request and locates the request resource. The server writes a copy of the resource to the TCP socket and the client reads it. A response consists of four parts: the status line, the response header, the blank line and the response data.

4. Release the connection TCP connection

If the connection mode is close, the server actively closes the TCP connection, and the client passively closes the connection, releasing the TCP connection; if the connection mode is keepalive, the connection will remain for a period of time during which you can continue to receive requests

5. Client browser parses HTML content

The client browser first parses the status line to see the status code indicating whether the request was successful or not. Each response header is then parsed, and the response header tells the following HTML document and its character set of several bytes. The client browser reads the response data HTML, formats it according to the syntax of HTML, and displays it in the browser window.

3. URL.URI.URNURIURI generally consists of three parts: the naming mechanism of ① accessing resources, the host name of ② to store resources, the name of ③ resources themselves, represented by the path, with emphasis on resources. URL uses URL to describe various information resources, including files, server addresses and directories, in a unified format. URL generally consists of three parts: the ① protocol (or service mode) ② stores the host IP address (and sometimes the port number) of the resource, and the specific address of the ③ host resource. URN,uniform resource name, such as directory and file name, unified resource naming, is to identify resources by name, URI is an abstract, high-level concept to define unified resource identification, while URL and URN are specific ways of resource identification. Both URL and URN are URI. Generally speaking, every URL is a URI, but not necessarily every URI is a URL. This is because URI also includes a subclass, uniform Resource name (URN), which names resources but does not specify how to locate them. The mailto, news, and isbn URI above are all examples of URN. Http transactions,

The response that contains a HTTP request and the corresponding request is called a http transaction, and it can also be understood that a http transaction is a complete process of HTTP request and HTTP response.

HTTP protocol by default, each transaction will open and close a new connection, so it takes a lot of time and bandwidth. Due to the slow start feature of TCP, the performance of each new connection is degraded, so the upper limit of the number of parallel connections that can be opened is limited. So using a persistent connection mode is a little better than not using a persistent connection by default, and its advantage is that it takes less time to request and disconnect from the tcp.

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

Servers

Wechat

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

12
Report