简体   繁体   English

application / * Content-Type和charset属性

[英]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规范的RFCRFC 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.

相关问题 应用程序的内容类型包括字符集 - Content-type for application includes charset Express:从 Content-Type &quot;application/json; charset=utf-8&quot; 中删除 charset=utf-8 - Express: Remove charset=utf-8 from Content-Type "application/json; charset=utf-8" Spring mvc web 服务给 Content-Type →text/html;charset=ISO-8859-1 预期是 [{&quot;key&quot;:&quot;Content-Type&quot;,&quot;value&quot;:&quot;application/json&quot;}] - Spring mvc web service gives Content-Type →text/html;charset=ISO-8859-1 expected is [{"key":"Content-Type","value":"application/json"}] 如何在OpenRasta中设置Content-Type标头字符集 - How to set Content-Type header charset in OpenRasta 无法解析对象,因为未在响应中指定未支持的Content-Type。 内容类型为&#39;text / html; charset = utf-8&#39; - Cannot parse object because no supported Content-Type was not specified in response. Content-Type was 'text/html;charset=utf-8' 内容类型:应用程序/pdf 更改为内容类型:应用程序/八位字节流 - Content-Type: application/pdf changing to Content-Type: application/octet-stream RESTEasy:找不到内容类型应用程序/json 类型的编写器 - RESTEasy: Could not find writer for content-type application/json type REST和内容类型 - REST and content-type 内容类型定界符 - Content-Type delimiter 如何在此请求中添加Content-Type application / json - How to add Content-Type application/json in this request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM