[英]application/* Content-Type and charset attributes
The RFC-2616 states in 3.7.1: RFC-2616在3.7.1中说明:
When no explicit charset parameter is provided by the sender, media subtypes of the "text" type are defined to have a default charset value of "ISO-8859-1" when received via HTTP. 当发送方未提供显式字符集参数时,“文本”类型的媒体子类型被定义为在通过HTTP接收时具有默认字符集值“ISO-8859-1”。
This is why I usually use eg text/plain; charset=utf-8
这就是为什么我通常使用例如text/plain; charset=utf-8
text/plain; charset=utf-8
as Content-Type
Header. text/plain; charset=utf-8
作为Content-Type
标题。
What about MediaTypes of type application
? application
类型的MediaTypes怎么样?
I often see und use headers like Content-Type: application/xml; charset=UTF-8
我经常看到像Content-Type: application/xml; charset=UTF-8
这样的头文件Content-Type: application/xml; charset=UTF-8
Content-Type: application/xml; charset=UTF-8
. Content-Type: application/xml; charset=UTF-8
。 RESTeasy 2.3.7 then forces the client to also send the charset parameter in the Accept
header. RESTeasy 2.3.7然后强制客户端也在Accept
标头中发送charset参数。 Otherwise it will answer with a 406
. 否则它将以406
回答。 RESTeasy 3.0.6 seems to be quite more tolearant here so I'm unsure what's the best practice here. RESTeasy 3.0.6在这里似乎更宽容,所以我不确定这里的最佳做法是什么。
RFC 2616 was obsoleted in June 2014 by a set of RFCs, where the one containing the general HTTP specifications is RFC 7213 . RFC 2616在2014年6月被一组RFC淘汰,其中包含一般HTTP规范的RFC是RFC 7213 。 Please use the RFC editor to check the current status of RFCs. 请使用RFC编辑器检查RFC的当前状态。
RFC 7213 explicitly says (in Appendix B): RFC 7213明确指出(在附录B中):
The default charset of ISO-8859-1 for text media types has been ISO-8859-1的默认字符集用于文本媒体类型
removed; 删除; the default is now whatever the media type definition says. 现在默认是媒体类型定义所说的。
On the other hand, RFC 6657 , while anticipating such changes, declares: 另一方面, RFC 6657虽然预见到了这些变化,但声明:
The default "charset" parameter value for "text/plain" is unchanged from [RFC2046] and remains as "US-ASCII". “text / plain”的默认“charset”参数值与[RFC2046]保持不变,并保持为“US-ASCII”。
Thus, if your data is not ASCII (= US-ASCII), you should keep declaring the charset
parameter explicitly. 因此,如果您的数据不是ASCII(= US-ASCII),则应该明确声明charset
参数。
The XML specification, clause 4.3.3 , specifies: XML规范,第4.3.3节 ,规定:
In the absence of external character encoding information (such as MIME headers), parsed entities which are stored in an encoding other than UTF-8 or UTF-16 MUST begin with a text declaration [...] containing an encoding declaration 在没有外部字符编码信息(例如MIME头)的情况下,以UTF-8或UTF-16以外的编码存储的解析实体必须以包含编码声明的文本声明开头。
So for XML transmitted over HTTP, irrespective of content type, the encoding MUST be explicitly set either in an HTTP header or in an encoding declaration, eg <?xml encoding='UTF-8'?>
. 因此,对于通过HTTP传输的XML,无论内容类型如何,编码必须在HTTP头或编码声明中明确设置,例如<?xml encoding='UTF-8'?>
。
For application
types in general, type-specific rules may apply. 对于一般的application
类型,可能适用特定于类型的规则。 Character encoding is irrelevant to most application
types, as the types define their own encoding schemes, including the encoding of any embedded character data. 字符编码与大多数application
类型无关,因为类型定义了自己的编码方案,包括任何嵌入字符数据的编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.