How to maintain the status between the HTTP client and the server, the client server

Source: Internet
Author: User

How to maintain the status (transfer) between the HTTP client and the server, the client server

The HTTP protocol and the status keep the HTTP protocol stateless. This is consistent with the original purpose of the HTTP protocol. The client simply needs to request the server to download some files, no client or server needs to record previous behaviors of each other,
Each request is independent, like the relationship between a customer and a vending machine or a common (non-member) hypermarket. But smart (or greedy ?) People soon discovered that providing on-Demand dynamic information will make the web more useful, just like adding the on-demand function to cable TV. This requirement forces HTML to gradually add client behaviors such as forms, scripts, and DOM,
On the other hand, the CGI specification appears on the server to respond to dynamic requests from the client. the HTTP protocol as the transmission carrier also adds the features of file upload and cookie. Among them, cookies are used to solve the stateless defects of HTTP.
As for the later session mechanism, it is another solution that maintains the status between the client and the server. Let's use several examples to describe the difference and connection between the cookie and session mechanism. I often went to a coffee shop and offered a free discount for five coffee cups. However, there is little chance of consuming five coffee cups at a time,
In this case, you need to record the consumption quantity of a customer in some way.
Imagine the following solutions: 1. the store clerk is very good and can remember the number of consumers each customer consumes. As long as the customer enters the coffee shop, the clerk knows what to do. This method is supported by the Protocol itself. 2. Send a card to the customer, which records the consumption quantity and generally has a validity period. For each consumption, if the customer shows this card, the current consumption will be associated with the previous or later consumption. This approach is to maintain the status on the client. 3. Send a membership card to the customer. No information except the card number is recorded. If the customer shows the card at each purchase, then the clerk finds the log corresponding to this card number in the store's record to add some consumption information. This approach is to maintain the status on the server side. Because the HTTP protocol is stateless and does not need to be stateful for various reasons, the next two solutions have become a realistic choice. Specifically, the cookie mechanism adopts the client-side persistence scheme,
The session mechanism adopts the server-side persistence scheme.
At the same time, we also see that because the server-side persistence scheme also needs to save an identifier on the client, the session mechanism may need to use the cookie Mechanism to save the identifier.

Related Article

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.