gpt4 book ai didi

HTTP header 换行样式

转载 作者:可可西里 更新时间:2023-11-01 15:03:07 26 4
gpt4 key购买 nike

哪种换行符样式更适合用于 HTTP header :\r\n\n,为什么?

最佳答案

\r\n,因为它在协议(protocol)规范中被定义为换行符。 RFC2616 states at the beginning of section 2.2, "Basic Rules" ,非常明确:

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

RFC2616 在技术上已被 RFC7230 淘汰,但它没有进行重大更改,并再次调用 CRLF 作为 section 3 中的分隔符。 ,并且该 RFC 引用 RFC5234, Appendix B.1将“CRLF”定义为 %x0D %x0A

然而,认识到人们出于任何目的都会违反标准,因此在 section 19.3 中有一个“容忍条款”。 (注意它重复了正确的序列):

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.

在较新的RFC7230, § 3.5

Although the line terminator for the start-line and header fields is the sequence CRLF, a recipient MAY recognize a single LF as a line terminator and ignore any preceding CR.

因此,除非您想成为邪恶的或以其他方式违反 RFC 的规则,否则请使用 \r\n

关于HTTP header 换行样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5757290/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com