在查找session和cookie的区别的资料时,有资料提到http是无状态的。我是不会忘记的,企鹅面试官问过我“http协议是有状态的还是无状态的”,我说不知道(之前没听说过)。后来想想那“404 Not Found”是什么意思,难道说http协议是有状态的?百度百科说:HTTP状态码(HTTP Status Code)是用以表示网页服务器HTTP响应状态的3位数字代码。不过我还是不明白哇。
无状态服务器是指一种把每个请求作为与之前任何请求都无关的独立的事务的服务器。
HTTP服务器就是一个例子。以URL形式提交的客户端请求可能包含cookies等带状态的数据,这些数据完全指定了所需的文档,而不需要其他之前请求的上下文或内存。
呃,说协议呢,干嘛扯到服务器上去哇,看英文版的维基百科吧
stateless protocal
In computing, a stateless protocol is a communications protocol that treats each request as an independent transaction that is unrelated to any previous request so that the communication consists of independent pairs of request and response. A stateless protocol does not require the server to retain session information or status about each communications partner for the duration of multiple requests.
An example of a stateless protocol is HTTP.[1] The protocol provides no means of storing a user's data between requests.
个人见解:Http状态码是在一次请求中服务器的响应状态(成功,请求错误什么的);http协议是无状态的是说http协议不记录历史的请求,就像指数函数一样,无记忆性。
Http状态码和http协议是无状态的说的就不是一回事。