HTTP protocol Basics

Source: Internet
Author: User
Tags ftp protocol

1 HTTP for communication between client and server segments

1.1 Client, server

One end of a resource that requests access to text or an image is called a client, and one end of the resource response is called a server-side

1.2 Request, Response

The client and server side communicate through the exchange of "request" and "response".

The client first begins to establish communication, and the server does not send a response until the request is received.

Request message:

Response message:


2 HTTP is a protocol that does not save state

With the HTTP protocol, whenever a new request is sent, a corresponding new response is generated. The protocol itself does not retain information on all previous requests or response messages.


3 HTTP method for informing server intent

3.1 Get: Get resources

The Get method is used to request a resource that has been identified by the URI, and the specified resource returns the response content after the server-side resolution process.

3.2 POST: Transport entity Body

The Post method is used to transfer entities of an entity. Although the body of the entity can also be transferred with the Get method, it is generally not transmitted by the Get method, but by the post method. Although post and get are similar, the main purpose of post is not to get the main content of the response.

3.3 PUT: Transferring files

The Put method is used to transfer files. Just like the FTP protocol file upload, it requires that the contents of the file be included in the body of the request message, and then saved to the location specified by the request URI.

3.4 HEAD: Get message header

The head method, like the Get method, simply does not return the main part of the text. Used to confirm the validity of the URI and the date and time of the resource update.

3.5 Delete: Deleting files

The Delete method is used to delete a file, which is the opposite of put. The Delete method deletes the specified resource by the request URI.

3.6 options: asking about supported methods

The options method is used to query the supported methods for the resources specified for the request URI.

3.7 Trace: Trace path

The trace method is a method that allows the Web server to loop back the previous request communication to the client.

When sending a request, fill in the number in the Max-froward header field, subtract the number by 1 on each server side, stop the transmission when the value is just minus 0 o'clock, and then return to the server side of the request.

The trace method is not often used, plus it tends to trigger xst (Cross-site tracing, cross-site tracking) attacks, which are usually less useful.

3.8 Connect: Require tunneling protocol to connect proxies

The Connect method requires a tunnel to be established when communicating with a proxy server to enable TCP communication with the tunneling protocol.


4 Durable connections Save traffic

4.1 http Initial version issue

In the initialization version of the HTTP protocol, the TCP connection is disconnected once per HTTP communication:

In the current year's communication situation, because it is very small text transmission, so even this is not much of a problem. With the popularity of HTTP, the document contains a lot of pictures of the situation is more:

4.2 Persistent connections

To solve the above TCP connection problem, http/1.1 came up with a method for persistent connections (HTTP persistent Connections, also known as HTTP keep-alive or HTTP Connection reuse). The feature of persistent connections is that the TCP connection state is maintained as long as the disconnect is not explicitly made at either end.

The benefit of persistent connections is that it reduces the additional overhead caused by the duplication and disconnection of TCP connections and reduces the load on the server side. In addition, the less expensive part of the time, so that the HTTP request and response can end earlier, so that the Web page display speed is correspondingly improved.

In http/1.1, all connections are persistent by default, but are not standardized within http/1.0. In addition to the server side, the client also needs to support persistent connections.

4.3 Pipeline

Persistent connections make it possible for most requests to be routed in a pipelined (pipelining) manner. Before sending a request, you wait and receive a response before sending the next request. After pipeline technology appears, you can send the next request without waiting for a response. This makes it possible to send multiple requests simultaneously in parallel without waiting for a response one after the other.

For example, when requesting an HTML Web page with 10 images, a persistent connection can make the request end faster than a single connection. Pipeline technology is faster than a durable connection. The more requests, the more obvious the time difference is.


5 State management Using cookies

HTTP is a stateless protocol, and the server side does not manage requests and responses that have occurred before. In other words, this request cannot be processed according to the previous request.

Admittedly, it is natural to reduce the CPU and memory resources consumed by the server because it does not have to be saved. In some cases, however, you need to control the state of the client. Therefore, the introduction of cookie technology.

Cookie technology controls the state of the client by writing cookie information in the request and response messages.

The cookie notifies the client to save the cookie based on a header field information called Set-cookie in the response message sent from the server side. When the next client sends a request to the server, the client automatically adds the cookie value to the request message and sends it out.

After the server-side discovers the cookie sent by the client, it checks the connection request from which client, then compares the records on the server, and finally obtains the related status information.

Related request-Response message content:


HTTP protocol Basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.