HTTP有HTTP cookie。cookie允许服务器跟踪用户状态、连接数、最后一个连接等。
HTTP具有持久连接(Keep-Alive),可以从同一个TCP连接发送多个请求。
HTTP有HTTP cookie。cookie允许服务器跟踪用户状态、连接数、最后一个连接等。
HTTP具有持久连接(Keep-Alive),可以从同一个TCP连接发送多个请求。
当前回答
什么是无状态?
一旦发出请求并将响应呈现回客户端,连接将被丢弃或终止。服务器将忘记所有关于请求者的信息。
为什么无状态? ?
web选择使用无状态协议。这是一个天才的选择,因为web的最初目标是允许文档(网页)被提供给非常大的用户。人们使用非常基本的硬件作为服务器。
维护长时间运行的连接将非常耗费资源。
如果web选择了有状态协议,那么为了维护访问者的连接,服务器上的负载将会增加。
其他回答
即使多个请求可以通过同一个HTTP连接发送,服务器也不会为它们通过同一个套接字到达附加任何特殊含义。这完全是一个性能问题,目的是尽量减少为每个请求重新建立连接所花费的时间/带宽。
就HTTP而言,它们仍然是独立的请求,并且必须包含足够的信息来满足请求。这就是“无国籍”的本质。如果没有服务器所知道的一些共享信息(在大多数情况下是cookie中的会话ID),请求将不会相互关联。
HTTP被称为无状态协议,因为每个请求都是独立执行的,不知道在它之前执行的请求,这意味着一旦事务结束,浏览器和服务器之间的连接也会丢失。
使协议无状态的原因是,在最初的设计中,HTTP是一个相对简单的文件传输协议:
请求一个以URL命名的文件, 获取响应文件, 断开连接。
一个连接和另一个连接之间没有保持任何关系,即使来自同一个客户机。这简化了客户端和服务器之间的契约,并且在许多情况下最大限度地减少了需要传输的数据量。
因为无状态协议不要求服务器在多个请求期间保留每个通信伙伴的会话信息或状态。
HTTP是一种无状态协议,这意味着一旦事务结束,浏览器和服务器之间的连接就会丢失。
HTTP无状态。TCP是有状态的。 没有所谓的HTTP连接,只有HTTP请求和HTTP响应。我们不需要维护任何东西来发出另一个HTTP请求。 “keep-alive”连接头意味着TCP将被后续的HTTP请求和响应重用,而不是一直断开和重新建立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.