How to maintain state between the HTTP client and the server side

Source: Internet
Author: User

HTTP protocol and the status of the HTTP protocol itself is stateless, which is consistent with the original purpose of the HTTP protocol, the client only need to simply request to the server to download some files, both the client and the server do not need to record each other's past behavior,
Each request is independent, like the relationship between a customer and a vending machine or an ordinary (non-membership) hypermarket. Yet clever (or greedy?) People quickly discovered that providing some on-demand dynamic information would make the web more useful, like adding on-demand functionality to cable TV. This demand, on the one hand, forces HTML to incrementally add client behaviors such as forms, scripts, and Dom.
On the other hand, the CGI specification appears on the server side in response to the client's dynamic request, and the HTTP protocol as the transmission carrier also adds file upload and cookie features. The purpose of the cookie is to resolve the HTTP protocol's stateless flaws in the efforts made.
The subsequent session mechanism is another solution for maintaining state between the client and the server. Let's use a few examples to describe the difference and connection between a cookie and a session mechanism. I used to go to a coffee shop to drink 5 cups of coffee free of charge for a cup of coffee concessions, but a one-time consumption of 5 cups of coffee, the opportunity is negligible,
There is a way to record the amount of a customer's consumption.
Imagine that there is no outside the following several options: 1, the shop staff is very strong, can remember the amount of each customer's consumption, as long as the customer into the coffee shop, the clerk will know how to treat. This approach is the protocol itself that supports the state. 2, issued to customers a card, the above record the amount of consumption, there is generally a valid period. If the customer presents this card each time it is consumed, the consumption will be linked to the previous or subsequent consumption. This practice is to keep the state on the client. 3, issued to the customer a membership card, in addition to the card number of what information is not recorded, each time the consumer, if the customer presented the card, the shop clerk in the store records found this card number corresponding record add some consumer information. This is done by keeping the state on the server side. Since the HTTP protocol is stateless and does not want to be stateful due to various considerations, the next two scenarios become a realistic choice. Specifically, the cookie mechanism uses a scheme that maintains state on the client,
The session mechanism uses a scenario that maintains state on the server side.
At the same time, we also see that because the server-side hold state of the scheme in the client also need to save an identity, so the session mechanism may need to use the cookie mechanism to achieve the purpose of preserving the identity

How to maintain state between HTTP client and server side (RPM)

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.