简体   繁体   English

字符集组件在HTTP内容类型标头中是否是必需的?

[英]Is the charset component mandatory in the HTTP content-type header?

An HTTP request might have the Content-Type header: HTTP请求可能具有Content-Type标头:

GET / HTTP/1.1
...
Content-Type: text/xml; charset=utf-8
...

Is there circumstances where the charset component is mandatory? 在某些情况下必须强制使用charset组件吗? in case, when? 万一什么时候?

Example of possibles Content-Type headers, not necessarily correct: 可能的Content-Type标头示例,不一定正确:

Content-Type: text/xml
Content-Type: charset=utf-8
Content-Type: text/xml; charset=utf8
Content-Type:

Standard info: 标准信息:

EDIT NOTE: It seem this reference is obsolete, RFC 7231 is the correct version now, as suggested by @RobbyCornelissen. 编辑说明:看来此引用已过时,RFC 7231现在是正确的版本,如@RobbyCornelissen所建议。

The Standard say rather little about this (or maybe I am looking in the wrong place): https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html 标准对此几乎没有说什么(或者我看错了地方): https : //www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

14.17 Content-Type 14.17内容类型

The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET. Content-Type实体标头字段指示发送给接收方的实体主体的媒体类型,或者在HEAD方法的情况下,指示如果请求是GET则应发送的媒体类型。

  Content-Type = "Content-Type" ":" media-type 

Media types are defined in section 3.7. 媒体类型在第3.7节中定义。 An example of the field is 该领域的一个例子是

  Content-Type: text/html; charset=ISO-8859-4 

Further discussion of methods for identifying the media type of an entity is provided in section 7.2.1. 在7.2.1节中将进一步讨论识别实体媒体类型的方法。

See RCF 7231, Appendix B. Changes from RFC 2616 : 请参阅RCF 7231,附录B。对RFC 2616的更改

The default charset of ISO-8859-1 for text media types has been removed; 文本媒体类型的默认ISO-8859-1字符集已删除; the default is now whatever the media type definition says . 现在默认值是媒体类型定义所说的 Likewise, special treatment of ISO-8859-1 has been removed from the Accept-Charset header field. 同样,已从Accept-Charset标头字段中删除了对ISO-8859-1的特殊处理。 (Section 3.1.1.3 and Section 5.3.3) (第3.1.1.3节和第5.3.3节)

So it depends on the default character set / encoding for the given media type. 因此,这取决于给定媒体类型的默认字符集/编码。 You can look up the media type registry with IANA , for example the application/xml media type , which links to RFC 7303 Section 3 : 您可以使用IANA查找媒体类型注册表 ,例如application / xml媒体类型 ,它链接到RFC 7303第3节

As many as three distinct sources of information about character encoding may be present for an XML MIME entity: a charset parameter, a BOM (see Section 3.3 below), and an XML encoding declaration (see Section 4.3.3 of [XML]). 一个XML MIME实体可能存在多达三个与字符编码有关的信息源:一个字符集参数,一个BOM(请参阅下面的3.3节)和一个XML编码声明(请参阅[XML]的4.3.3节)。 Ensuring consistency among these sources requires coordination between entity authors and MIME agents (that is, processes that package, transfer, deliver, and/or receive MIME entities). 要确保这些源之间的一致性,需要在实体作者与MIME代理(即打包,传输,传递和/或接收MIME实体的过程)之间进行协调。

The use of UTF-8, without a BOM, is RECOMMENDED for all XML MIME entities. 建议对所有XML MIME实体使用不带BOM的UTF-8。

So no, it's not mandatory, but if omitted, it depends on the specific media type how you can detect it. 因此,不是强制性的,但如果省略,则取决于如何检测特定媒体类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM