问题描述
我有点困惑。有人可以向我解释这两种响应状态之间的区别是什么:
I am a bit confused. Could somebody please explain to me what's the difference between these two response statuses:
HTTP/1.1 101 Web Socket Protocol Handshake
HTTP/1.1 101 Switching Protocols
我得到的回复是否重要?
Does it matter what response I get?
推荐答案
没有任何区别。重要的是 101
响应代码,表明握手正在进行中。这在中定义:
There is no difference whatsoever. What is important is the 101
response code to indicate the handshake is progressing. This is defined in RFC 6455:
...
来自服务器的握手比客户端握手简单得多。 第一行是HTTP状态行,状态代码为101:
The handshake from the server is much simpler than the client handshake. The first line is an HTTP Status-Line, with the status code 101:
HTTP / 1.1 101切换协议
HTTP/1.1 101 Switching Protocols
除101之外的任何状态代码表示WebSocket握手尚未完成且HTTP的语义仍然适用。
Any status code other than 101 indicates that the WebSocket handshake has not completed and that the semantics of HTTP still apply.
Status-Line
的文本是任意的,服务器可以使用它想要的任何文本,每:
The text of the Status-Line
is arbitrary, the server can use whatever text it wants, per RFC 2616:
...
状态-Code元素是尝试理解和满足请求的3位整数结果代码。这些代码在第10节中完全定义。原因 - 短语旨在提供状态代码的简短文本描述。 Status-Code旨在供自动机使用, Reason-Phrase适用于人类用户。客户无需检查或显示Reason-Phrase。
The Status-Code element is a 3-digit integer result code of the attempt to understand and satisfy the request. These codes are fully defined in section 10. The Reason-Phrase is intended to give a short textual description of the Status-Code. The Status-Code is intended for use by automata and the Reason-Phrase is intended for the human user. The client is not required to examine or display the Reason-Phrase.
切换协议
恰好是中使用的示例,但那是不是要求。
Switching Protocols
just happens to be what the examples in RFC 6455 use, but that is not a requirement.
这篇关于Web套接字协议握手与交换协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!