HTTP有HTTP cookie。cookie允许服务器跟踪用户状态、连接数、最后一个连接等。
HTTP具有持久连接(Keep-Alive),可以从同一个TCP连接发送多个请求。
HTTP有HTTP cookie。cookie允许服务器跟踪用户状态、连接数、最后一个连接等。
HTTP具有持久连接(Keep-Alive),可以从同一个TCP连接发送多个请求。
当前回答
从维基百科:
HTTP is a stateless protocol. A stateless protocol does not require the server to retain information or status about each user for the duration of multiple requests. But some web applications may have to track the user's progress from page to page, for example when a web server is required to customize the content of a web page for a user. Solutions for these cases include: the use of HTTP cookies. server side sessions, hidden variables (when the current page contains a form), and URL-rewriting using URI-encoded parameters, e.g., /index.php?session_id=some_unique_session_code.
What makes the protocol stateless is that the server is not required to track state over multiple requests, not that it cannot do so if it wants to. This simplifies the contract between client and server, and in many cases (for instance serving up static data over a CDN) minimizes the amount of data that needs to be transferred. If servers were required to maintain the state of clients' visits the structure of issuing and responding to requests would be more complex. As it is, the simplicity of the model is one of its greatest features.
其他回答
HTTP被称为无状态协议,因为每个请求都是独立执行的,不知道在它之前执行的请求,这意味着一旦事务结束,浏览器和服务器之间的连接也会丢失。
使协议无状态的原因是,在最初的设计中,HTTP是一个相对简单的文件传输协议:
请求一个以URL命名的文件, 获取响应文件, 断开连接。
一个连接和另一个连接之间没有保持任何关系,即使来自同一个客户机。这简化了客户端和服务器之间的契约,并且在许多情况下最大限度地减少了需要传输的数据量。
因为无状态协议不要求服务器在多个请求期间保留每个通信伙伴的会话信息或状态。
HTTP是一种无状态协议,这意味着一旦事务结束,浏览器和服务器之间的连接就会丢失。
如果协议HTTP被指定为状态全协议,浏览器窗口将使用单一连接与web服务器通信,以便向web应用程序发送多个请求。这使浏览器窗口有机会长时间地连接浏览器窗口和web服务器,并使它们长时间处于空闲状态。这可能会导致在客户端大部分连接空闲的情况下,web服务器的连接达到最大值。
我认为有人为无状态概念选择了一个非常不幸的名字,这就是造成整个误解的原因。它不是关于存储任何类型的资源,而是关于客户端和服务器之间的关系。
客户:我把所有的资源都保留在我这边,把所有需要处理的重要项目的“清单”发给你。做好你的工作。
服务员:好的。让我来负责筛选哪些是重要的,然后给你适当的答复。
这意味着服务器是客户端的“奴隶”,在每次请求后都必须忘记他的“主人”。实际上,STATELESS仅指服务器的状态。
https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_1_3
从维基百科:
HTTP is a stateless protocol. A stateless protocol does not require the server to retain information or status about each user for the duration of multiple requests. But some web applications may have to track the user's progress from page to page, for example when a web server is required to customize the content of a web page for a user. Solutions for these cases include: the use of HTTP cookies. server side sessions, hidden variables (when the current page contains a form), and URL-rewriting using URI-encoded parameters, e.g., /index.php?session_id=some_unique_session_code.
What makes the protocol stateless is that the server is not required to track state over multiple requests, not that it cannot do so if it wants to. This simplifies the contract between client and server, and in many cases (for instance serving up static data over a CDN) minimizes the amount of data that needs to be transferred. If servers were required to maintain the state of clients' visits the structure of issuing and responding to requests would be more complex. As it is, the simplicity of the model is one of its greatest features.