HTTP标头区分大小写吗? [英] Are HTTP headers case-sensitive?
问题描述
在博客文章中,我使用以下PHP设置响应的内容类型:
In a blog post I use the following PHP to set the content-type of a response:
header('content-type: application/json; charset=utf-8');
我刚收到该帖子的评论说 content-type
需要大写, Content-type
。它是否正确?它似乎适用于所有小写的我,我假设HTTP标题不区分大小写。或者它是否正常工作,因为浏览器很好?
I just got a comment on that post saying that content-type
needs to be capitalized, Content-type
. Is this correct? It seems to work for me with all lower-case, and I assumed the HTTP headers were case-insensitive. Or does it just work because browsers are nice?
推荐答案
来自 RFC 2616 - 超文本传输协议 - HTTP / 1.1,第4.2节消息标题:
每个标题字段由名称后跟冒号(:)和字段值组成。字段名称不区分大小写。
Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive.
更新RFC 7230未列出任何来自RFC 2616的更改。
The updating RFC 7230 does not list any changes from RFC 2616 at this part.
这篇关于HTTP标头区分大小写吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!