为什么说“HTTP是无状态协议"? [英] Why is it said that "HTTP is a stateless protocol"?

查看:43
本文介绍了为什么说“HTTP是无状态协议"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTTP 具有 HTTP Cookie.Cookie 允许服务器跟踪用户状态、连接数、上次连接等.

HTTP has HTTP Cookies. Cookies allow the server to track the user state, the number of connections, last connection, etc.

HTTP 具有持久连接 (Keep-Alive),其中可以从同一个 TCP 连接发送多个请求.

HTTP has persistent connections (Keep-Alive) where several requests can be sent from the same TCP Connection.

推荐答案

即使多个请求可以通过同一个 HTTP 连接发送,服务器并没有为它们通过同一个套接字到达附加任何特殊含义.这仅仅是一个性能问题,旨在最大限度地减少时间/带宽,否则会花费在为每个请求重新建立连接上.

Even though multiple requests can be sent over the same HTTP connection, the server does not attach any special meaning to their arriving over the same socket. That is solely a performance thing, intended to minimize the time/bandwidth that'd otherwise be spent reestablishing a connection for each request.

就 HTTP 而言,它们仍然是独立的请求,并且它们自身必须包含足够的信息来满足请求.这就是无国籍"的本质.如果没有服务器知道的一些共享信息,请求将不会相互关联,在大多数情况下,这些信息是 cookie 中的会话 ID.

As far as HTTP is concerned, they are all still separate requests and must contain enough information on their own to fulfill the request. That is the essence of "statelessness". Requests will not be associated with each other absent some shared info the server knows about, which in most cases is a session ID in a cookie.

这篇关于为什么说“HTTP是无状态协议"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆