HTTP protocol is stateless protocol, how to understand?

Source: Internet
Author: User

HTTP is a stateless protocol, with two consecutive requests for the same session that are not known to each other, and they are parsed by the newly instantiated environment, which does not save any information about the session, except that the application itself may have all the information stored in the global object.

Own understanding, In asp: Each time the page is submitted to the server does not have any relationship, each time the information recorded on the page will not be remembered, (except that the app itself may have been stored in the global object of all the information) in. NET is actually viewstate,viewstate is the ASP. The basic unit of interest, which is stored in the hidden field of the control, etc.

The state of the Protocol refers to the ability of the next transmission to "remember" the transmission of the information.
HTTP is not to maintain the information transmitted by this connection for the next connection.

Stateless means that when the browser sends a request to the server, the server responds, but when the same browser sends the request to the server, he responds, but he does not know that you are just the browser, simply, that the server will not remember you, so it is a stateless protocol.
DNS is a stateful protocol.

HTTP is an object-oriented protocol belonging to the application layer, the HTTP protocol one has five characteristics, 1, support customer/server mode, 2, simple high-speed, 3, flexible, 4, no connection, 5, stateless; "Stateless" is one of the main features of the HTTP protocol, the following is "stateless" The explanation. No status: Refers to the

The protocol has no memory capacity for transactional processing. A lack of state means that assuming that the preceding information may be processed, it must be re-routed, which could result in an increase in the amount of data sent per connection. On the other hand, when the server does not need the previous information, it responds faster.

HTTP is the abbreviation for Hyper Text Transfer protocol, which, as its name implies, supports the transmission of hypertext. So what is hypertext? To be blunt is to use HTML to write pages. Typically, we use the client browser to access server resources, and the most common URLs are HTML-suffixed files. Therefore, we can say that hypertext is the most basic resource on the network.

Since the purpose of the HTTP protocol is to support the transmission of hypertext, more broadly, is to support the transfer of resources, then in the client browser to send a request to Httpserver, and then httpserver the corresponding resources sent back to the client, such a process, Regardless of the client or server, there is no need to record this process, because each request and response is relatively independent, as if you are in front of the vending machine to drop coins to buy goods, no one will not need to remember such a transaction process. In general, a URL corresponding to the unique hypertext, and Httpserver is absolutely fair and impartial, regardless of whether you are Michael, or Jordon, it will return the same hypertext based on the URL request received. It is this uniqueness that makes it meaningless to record the behavior of the user, so the HTTP protocol is designed as a stateless connection protocol that meets its own needs.

< Span style= "Background-color:rgb (255,255,255)" >         However, over time, It is found that static HTML is boring and tedious, and adding dynamically generated content will make Web applications more practical. Thus, the syntax of HTML is expanding, the most important thing is to add a form (form), the client also added such as script processing, DOM processing and other functions, for the server, there is a corresponding CGI (Common Gateway Interface) to handle dynamic requests, including form submissions. After the advent of a Web application in which the client interacts dynamically with the server, the HTTP stateless nature of the application is a serious impediment to the implementation of these applications, after all, the interaction is necessary, and the simple shopping cart program also needs to know what product the user has chosen before. As a result, two techniques for keeping the HTTP connection state are created, one is a cookie, and the other is a session.

A cookie is a solution that maintains state through the client. By definition, a cookie is a special message that is sent to the client by the server, which is stored in the client as a text file, and the client brings these special information each time it sends a request to the server. Let's be more specific: when a user visits a site that supports cookies using a browser, the user provides personal information including username and submits it to the server; The server will also send back this personal information at the same time as the hypertext corresponding to the client, which is not stored in the HTTP response body (Response body), but in the HTTP response header (Response header). When the client browser receives a response from the server, the browser stores the information in a unified location, and for the Windows operating system, we are able to: [System disk]:\documents and Settings\[username]\ Cookies are found in the cookie folder, and since then, 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.
With the help of a cookie, when the server receives a request from the client browser, it generates the client-specific information by analyzing the cookie that is stored in the request header, thereby dynamically generating the corresponding content from the client. In general, we can see the "Please remember Me" option from the login interface of a very multi-site, assuming that you check it before you log in, then the next time you visit the site there will be no need for repeated and cumbersome login action, and this feature is implemented through a cookie.

One solution that is relative to a cookie is the session, which is maintained by the server. Because the term of the session includes a lot of semantics, you need to understand the meaning of the session here. First, we usually translate sessions into conversations, so we can refer to a series of interactions between the client browser and the server as a session. From this semantics, we will refer to the duration of the session, what is done during the session and so on, and second, the session refers to the server side for the client to open up the storage space, in which the information is used to hold the state. From this semantics, we will refer to what is stored in the session, how to get the matching content from the session according to the key value.
To use the session, the first step is of course to create a session. So when is the session created? Of course, it is created in the process of server-side program execution, the different language implementation of the application has different methods to create the session, and in Java by calling HttpServletRequest's GetSession method (using True as a parameter) was created. At the same time that the session was created, the server generates a unique session ID for the session, which is used in subsequent requests to get the session that was created again, and after the session is created, will be able to invoke the session-related methods to add content to the session, which will only be stored in the server, the client only has the session ID, when the client sends the request again, the session ID will be taken, Once the server accepts the request, it finds the corresponding session based on the session ID, which is used again. Formally, the state of the user is maintained. There's more to the session, and I'll continue to talk about it later in the post.

In summary, HTTP itself is a stateless connection protocol, in order to support the interaction between the client and server, we need to use different technologies for the interactive storage state, and these different technologies are the cookie and the session

HTTP protocol is stateless protocol, how to understand?

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.