HTTP stateless protocol

Source: Internet
Author: User

HTTP is a stateless protocol.

Stateless means that the Protocol has no memory for transaction processing. The lack of status means that if subsequent processing requires the previous information, it must be re-transmitted, which may increase the amount of data transmitted each connection. On the other hand, when the server does not need previous information, its response is faster.

Web applications with dynamic interaction between clients and serversProgramAfter the emergence, the stateless HTTP feature severely hinders the implementation of these applications. After all, interaction must be carried forward. A simple Shopping Cart program also needs to know what products the user has chosen before. Therefore, the two technologies used to maintain the HTTP connection status came into being. One is cookie, and the other is session. HTTP itself is a stateless connection protocol. to support interaction between the client and the server, we need to use different technologies for interactive storage, these different technologies are cookie and session.

Cookie is a solution that maintains the status through the client. By definition, cookies are the special information sent from the server to the client, which is stored on the client as text files, the client then carries the special information each time it sends a request to the server. Let's be more specific: when a user accesses a website that supports cookies through a browser, the user will provide personal information including the user name and submit it to the server. Then, when the server returns the corresponding hypertext to the client, it also sends back the personal information. Of course, this information is not stored in the HTTP response body (Response
Is stored in the HTTP Response Header (response ).
When the client browser receives a response from the server, the browser stores the information in a unified location. For a Windows operating system, we can:
[System Disk]: \ Documents ents and
The stored cookie is found in the Settings \ [user name] \ cookies directory. When the client sends a request to the server, the corresponding cookie is sent back to the server. This time, the cookie information is stored in the HTTP Request Header (Request
Header.

With the implementation of cookie technology, after receiving a request from a client browser, the server can analyze the cookie stored in the request header to obtain the unique information of the client, in this way, content corresponding to the client is dynamically generated. Generally, we can see the option "remember me" in the logon interface of many websites. If you select this option, log on again, therefore, the next time you access the website, you do not need to perform repeated and cumbersome logon actions. This function is implemented through cookies.

A solution opposite to Cookie is Session, which is maintained by the server. The session vocabulary contains a lot of semantics, so we need to clarify it here.
The meaning of the session. First, we usually translate sessions into sessions, so we can call a series of interactions between the client browser and the server
Session. Starting from this semantics, we will mention the session duration and the operations performed in the session process. Secondly, session refers to the storage space opened by the server for the client. The information stored in the session is used to maintain the status. Starting from this semantics, we will mention what content is stored in the session and how
Obtain the matched content in the session.

The first step is to create a session. When will the session be created? Of course, it was created during the running of the server program. applications implemented in different languages have different methods to create sessions, in Java, it is created by calling the getsession method of httpservletrequest (using true as the parameter. When a session is created, the server generates a unique session for the session.
ID, and this session
The ID will be used in subsequent requests to obtain the created session. After the session is created, you can call the session-related method to add content to the session, the content is only stored on the server, and only sessions are sent to the client.
Id. When the client sends the request again, the session ID is taken. After the server receives the request
ID to find the corresponding session and use it again. In this process, the user's status is maintained. There are still a lot of session-related content. I will continue to talk about it in future post.

To sum up, HTTP itself is a stateless connection protocol. to support interaction between the client and the server, we need to use different technologies to store the status of interaction, these different technologies are cookie and session.

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.