HTTP标题行中断样式 [英] HTTP header line break style
问题描述
在HTTP标头中使用哪种换行符样式更可取: \\\\ n
或 \ n
,为什么?
Which line break style is preferable for use in HTTP headers: \r\n
or \n
, and why?
推荐答案
\\\\ n
,因为它被定义为协议规范中的换行符。 RFC2616在第2.2节(基本规则(!))的开头陈述,非常明确地:
\r\n
, because it's defined as the line break in the protocol specification. RFC2616 states at the beginning of Section 2.2 (Basic Rules (!)), quite unambiguously:
CR =< US-ASCII CR,回车(13)>
LF = < US-ASCII LF,linefeed(10)>
HTTP / 1.1将序列CR LF定义为除了entity-body
CR = <US-ASCII CR, carriage return (13)>
LF = <US-ASCII LF, linefeed (10)>
HTTP/1.1 defines the sequence CR LF as the end-of-line marker for all protocol elements except the entity-body
但是,认识到人们会出于任何目的打破标准,第19.3节(请注意,它会重新迭代正确的序列):
However, recognizing that people will break the standard for whatever purposes, there is a "tolerance provision" in Section 19.3 (note that it re-iterates the correct sequence):
消息头字段的行终止符是序列CRLF。但是,我们建议应用程序在解析此类头时,将单个LF识别为行终止符并忽略前导CR。
The line terminator for message-header fields is the sequence CRLF. However, we recommend that applications, when parsing such headers, recognize a single LF as a line terminator and ignore the leading CR.
因此,除非您想成为邪恶或以其他方式违反RFC的规则,请使用 \ r \ n
。
Therefore, unless you want to be Evil or otherwise break the RFC's rules, use \r\n
.
这篇关于HTTP标题行中断样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!