HTTP methods and protocols

What is HTTP?

The Hypertext Transfer Protocol (HTTP) was designed to ensure communication between clients and servers.

The way HTTP works is a request-response protocol between client and server.

A web browser may be the client, and a web application on your computer may be the server.

Example: The client (browser) submits an HTTP request to the server; the server returns a response to the client. The response contains status information about the request and what may have been requested.

 

【Stateless Protocol】

In the HTTP protocol, the client always initiates the request and the server sends back the response.

This limits the use of the HTTP protocol, and it is impossible for the server to push messages to the client when the client does not initiate a request.

The HTTP protocol is a stateless protocol, and this request from the same client has no correspondence with the previous request.

HTTP is an application layer protocol consisting of requests and responses, and is a standard client-server model. HTTP is a stateless protocol.

 

【Version History】

Hypertext Transfer Protocol has evolved many versions, most of them are backward compatible.

 

[HTTP source and function:]

All WWW documents must comply with this standard. HTTP was originally designed to provide a way to publish and receive HTML pages. HTTP is a client-side and server-side request and response standard (TCP). The client is the end user and the server is the website. Using a web browser, web crawler, or other tool, the client initiates an HTTP request to the server on the specified port (the default port is 80). (We call this client) a user agent. The responding server has (some) resources stored on it, such as HTML files and images. (We call) this answering server the origin server. There may be multiple intermediaries between the user agent and the origin server, such as proxies, gateways, or tunnels. Although the TCP/IP protocol is the most popular application on the Internet, the HTTP protocol does not dictate that it must be used and (based on) the layers it supports. In fact, HTTP can be implemented over any other internet protocol, or over other networks. HTTP only assumes (and its underlying protocols provide) reliable transport, and any protocol that can provide this guarantee can be used by it.

Typically, an HTTP client initiates a request to establish a TCP connection to the server's specified port (port 80 by default). The HTTP server listens on that port for requests sent by the client. Upon receiving the request, the server sends back (to the client) a status line, such as "HTTP/1.1 200 OK", and a (response) message whose body may be the requested file, an error message, or some other information .

The reason HTTP uses TCP instead of UDP is that (to open) a web page must transmit a lot of data, and the TCP protocol provides transmission control, organizing data in order, and error correction.

 

[URL function:]

Identifies the resource requested by the HTTP or HTTPS protocol

 

【HTTP protocol function】

The HTTP protocol (HyperText Transfer Protocol) is a transfer protocol for transferring hypertext from a WWW server to a local browser. It can make the browser more efficient and reduce network traffic. It not only ensures that the computer transmits hypertext documents correctly and quickly, but also determines which part of the document is transmitted, and which part of the content is displayed first (eg, text before graphics).

HTTP is an application-layer communication protocol between a client browser or other program and a web server.

All hypertext information is stored on the Web server on the Internet, and the client needs to transmit the hypertext information to be accessed through the HTTP protocol. HTTP contains commands and transmission information, which can be used not only for Web access, but also for communication between other Internet/intranet application systems, so as to realize the integration of hypermedia access to various application resources.

The website address we enter in the address bar of the browser is called URL (Uniform Resource Locator). Just like every household has a house number address, every web page also has an Internet address. when you are

When you enter a URL in the browser's address box or click a hyperlink, the URL determines the address to browse. The browser extracts the web page code of the site on the web server through the Hypertext Transfer Protocol (HTTP) and translates it into a beautiful web page.

 

【Agreement Basics】

HTTP (HyperText Transport Protocol) is the abbreviation of HyperText Transport Protocol, which is used to transmit WWW data. For details of HTTP protocol, please refer to RFC2616. The HTTP protocol adopts a request/response model.

The client sends a request to the server, and the request header contains the requested method, URL, protocol version, and a MIME-like message structure containing request modifiers, client information, and content. The server responds with a status line containing the message protocol version, success or error code plus server information, entity meta information, and possibly entity content.

Usually HTTP messages include request messages from the client to the server and response messages from the server to the client.

Both types of messages consist of a start line, one or more header fields, a blank line indicating the end of the header fields, and an optional message body. The HTTP header field includes four parts: general header, request header, response header and entity header.

Each header field consists of a domain name, a colon (:) and a field value. Domain names are case-insensitive. Any number of spaces may be added before the field value. Header fields may be extended over multiple lines, using at least one space or tab at the beginning of each line.

 

【working principle】

An HTTP operation is called a transaction, and its working process can be divided into four steps:

① First, the client and the server need to establish a connection. As soon as a hyperlink is clicked, the work of HTTP begins.

After establishing the connection

② The client sends a request to the server in the format of: Uniform Resource Identifier (URL), protocol version number, followed by MIME information including request modifiers, client information and possible content.

③ After the server receives the request, it gives the corresponding response information in the form of a status line, including the protocol version number of the information, a success or error code, followed by MIME information including server information, entity information and possible content.

④ The client receives the information returned by the server and displays it on the user's display screen through the browser, and then the client disconnects from the server.

 

    If an error occurs in one of the above steps, the error message will be returned to the client and output by the display. For users, these processes are completed by HTTP itself. Users only need to click with the mouse and wait for the information to be displayed.

    Many HTTP communications are initiated by a user agent and include a request for a resource on the origin server. In the simplest case this is probably done over a separate connection between the user agent and the server. On the Internet, HTTP communication usually occurs over a TCP/IP connection. The default port is TCP 80, but other ports are available. But this does not indicate that the HTTP protocol can be completed on top of other protocols on the Internet or other networks. HTTP only heralds a reliable transport.

    This process is like when we call to order. We can call the merchant and tell him what specifications we need, and then the merchant will tell us which items are in stock and which items are out of stock. These, we contact by telephone through the telephone line (HTTP is through TCP/IP), of course, we can also fax, as long as the business side also has faxes.

 

[The two most commonly used HTTP methods are: GET and POST]

The two most commonly used methods for request-response between client and server are: GET and POST

①GET - Request data from the specified resource and send it in the requested URL

②POST - Submit the data to be processed to the specified resource and send it in the HTTP request body

(1) GET method

Note that the query string (name/value pair) is sent in the URL of the GET request:

/test/demo_form.asp?name1=value1&name2=value2

Some other notes about GET requests:

GET requests can be cached

GET requests remain in browser history

GET requests can be bookmarked

GET requests should not be used when dealing with sensitive data

GET requests have a length limit

GET requests should only be used to retrieve data

(2) POST method

Note that the query string (name/value pair) is sent in the HTTP message body of the POST request:

POST /test/demo_form.asp HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2

Some other notes about POST requests:

POST requests are not cached

POST requests are not kept in browser history

POST cannot be bookmarked

POST requests do not require data length

 

【Compare GET and POST】

The table below compares two HTTP methods: GET and POST

  GET POST
back button/refresh harmless The data will be resubmitted (the browser should inform the user that the data will be resubmitted).
bookmark bookmarkable Not bookmarked
cache can be cached cannot be cached
encoding type application/x-www-form-urlencoded application/x-www-form-urlencoded or multipart/form-data. Use multiple encodings for binary data.
history Parameters are preserved in the browser history. Parameters are not saved in browser history.
restrictions on data length Yes. When sending data, the GET method adds data to the URL; the length of the URL is limited (the maximum URL length is 2048 characters). Unlimited.
Restrictions on data types Only ASCII characters are allowed. no limit. Binary data is also allowed.
safety

GET is less secure than POST because the data sent is part of the URL.

Never use GET when sending passwords or other sensitive information!

POST is more secure than GET because parameters are not saved in browser history or web server logs.
visibility The data is visible to everyone in the URL. Data will not be displayed in the URL.

 

[Other HTTP request methods]

The following table lists some other HTTP request methods:

Method description
HEAD Same as GET, but returns only the HTTP headers, not the document body.
PUT Upload the specified URI representation.
DELETE Delete the specified resource.
OPTIONS Returns the HTTP methods supported by the server.
CONNECT Convert the request connection to a transparent TCP/IP channel.

 

 

 

 

 

[Extension: HTTP Proxy Server]

(1) Introduction and composition

The full name of the proxy server in English is Proxy Server, and its function is to proxy network users to obtain network information. Figuratively speaking: it is a transfer station for network information.

The proxy server is a server between the browser and the web server. With it, the browser does not directly go to the web server to retrieve the web page, but sends a request to the proxy server. The Request signal will be sent to the proxy server first. The proxy server retrieves the information required by the browser and transmits it to your browser.

Moreover, most proxy servers have the function of buffering, just like a large Cache, which has a large storage space, and it continuously stores the newly obtained data to its local memory. If the data requested by the browser is If it already exists and is up-to-date in its local memory, it does not fetch data from the Web server again, but directly transmits the data in the memory to the user's browser, which can significantly improve browsing speed and efficiency.

More importantly: Proxy Server (proxy server) is an important security function provided by the Internet link-level gateway, and its work is mainly in the dialogue layer of the Open System Interconnection (OSI) model.

(2) The main functions of the http proxy server:

The main functions are as follows:

① Break through your own IP access restrictions and visit foreign sites. Such as: Education Network, 169 Network and other network users can access foreign websites through agents;

② To access internal resources of some units or groups, such as a university FTP (provided that the proxy address is within the allowable access range of the resource), using a free proxy server in the address segment of the education network can be used for various open to the education network. FTP-like download and upload, as well as various data query and sharing services;

③Break through China Telecom's IP blockade: China Telecom users have many websites that are restricted from accessing. This restriction is artificial, and different Serves block addresses differently. So if you can't access it, you can try a foreign proxy server;

④Improve the access speed: Usually the proxy server sets a large hard disk buffer. When there is information from the outside world, it also saves it in the buffer. When other users access the same information, the buffer is directly used. Take out information from the area and pass it to the user to improve the access speed;

⑤Hide the real IP: Internet users can also hide their IP in this way to avoid attacks.

(3) http proxy icon:

 

 

[Extension: Implementation of Virtual Hosting]

(1) Introduction and composition:

Virtual host: It is to divide a certain disk space on the network server for users to place sites, application components, etc., and provide necessary site functions and data storage and transmission functions.  

The so-called virtual host, also called "website", is to divide a server running on the Internet into multiple "virtual" servers, each of which has an independent domain name and a complete Internet server (supporting WWW, FTP, E-mail, etc.) function. Different virtual hosts on a server are independent and managed by users themselves. But a server host can only support a certain number of virtual hosts, when the number is exceeded, users will experience a sharp drop in performance.

(2) Principle:

Virtual hosting is a technology that uses the same WEB server to provide services for websites with different domain names. Apache, Tomcat, etc. can implement this function through configuration.

Related HTTP header: Host.

For example: Host: www.baidu.com

When the client sends an HTTP request, it will carry the Host header, which records the domain name entered by the client. In this way, the server can confirm which domain name the client wants to access based on the Host header.

 

 

【HATE】

Let's compare the difference between URL and URI

For details, I will summarize in the following article.

 

【Summarize:】

①The text in the webpage takes precedence over the image display Reason: The HTTP protocol can determine which part of the transmitted document is displayed first

②Proxy server: It can break through its own IP access restrictions and access foreign sites. Its work is mainly in the dialogue layer of the Open System Interconnection (OSI) model.

③ The corresponding HTTP is the application layer communication protocol between the client browser or other program and the Web server

④Virtual host: A server host can only support a certain number of virtual hosts. When this number is exceeded, the user will experience a sharp drop in performance.

⑤ URL Uniform Resource Locator, URI Uniform Resource Identifier

 

.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326263953&siteId=291194637