我应该为HTTP标头使用什么字符编码? [英] What character encoding should I use for a HTTP header?

查看:116
本文介绍了我应该为HTTP标头使用什么字符编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用有趣的HTML特殊字符(✰)(请参阅 http://html5boilerplate.com/获取更多信息)服务器 HTTP标头,我想知道每个规格是否允许。

I'm using a "fun" HTML special-character (✰)(see http://html5boilerplate.com/ for more info) for a Server HTTP-header and am wondering if it is "allowed" per spec.


  • 在Windows Xp Pro SP 3上的Chrome中使用开发工具中的网络选项卡我看到✰很好。

  • Using the Network Tab in the dev tools in Chrome on Windows Xp Pro SP 3 I see the ✰ just fine.

在IE8中,✰ <\\ n> 正确呈现。

In IE8 the ✰ is not rendered correctly.

w3.org HTML验证器正确渲染(显示â)。

The w3.org HTML validator does not render it correctly (displays "â°" instead).

现在,我不太热衷于角色编码......坦率地说,我并不太关心他们;我只是盲目地使用UTF-8 cus我被告知。 : - )

Now, I'm not too keen on character encodings ... and frankly I don't really care too much about them; I just blindly use UTF-8 cus I'm told to. :-)

由不同解析器/浏览/引擎/中的错误导致的差异(无论如何 - 他们被称为?

是否有针对此标题的规范,或者是HTTP标头值的允许字符列表?

推荐答案

简而言之:只保证ASCII能够正常工作。一些非ASCII字节允许向后兼容,但不应该是可显示的。

In short: Only ASCII is guaranteed to work. Some non-ASCII bytes are allowed for backwards compatibility, but are not supposed to be displayable.

HTMLTP放弃了并指定在标题中除了ASCII之外没有有用的编码:

HTTPbis gave up and specified that in the headers there is no useful encoding besides ASCII:


历史上,HTTP允许在
ISO-8859-1字符集[ISO-8859-1]中使用文本的字段内容,通过使用[RFC2047]编码支持其他字符集仅
。实际上,大多数HTTP头
字段值仅使用US-ASCII字符集[USASCII]的子集。
新定义的头字段应该将它们的字段值限制为
US-ASCII八位字节。收件人应该将字段
内容(obs-text)中的其他八位字节视为不透明数据。

Historically, HTTP has allowed field content with text in the ISO-8859-1 charset [ISO-8859-1], supporting other charsets only through use of [RFC2047] encoding. In practice, most HTTP header field values use only a subset of the US-ASCII charset [USASCII]. Newly defined header fields SHOULD limit their field values to US-ASCII octets. A recipient SHOULD treat other octets in field content (obs-text) as opaque data.






以前,1999年的RFC 2616定义了这个:


Previously, RFC 2616 from 1999 defined this:


* TEXT的字可能包含ISO以外的字符集中的字符 -
8859-1 [22]仅在根据RFC 2047 [14]的规则编码时。

Words of *TEXT MAY contain characters from character sets other than ISO- 8859-1 [22] only when encoded according to the rules of RFC 2047 [14].

和RFC 2047是 MIME编码,所以它是:

and RFC 2047 is the MIME encoding, so it'd be:

=?UTF-8?Q?=E2=9C=B0?=

但我不认为很多(如果有的话)客户支持它。

but I don't think that many (if any) clients support it.

这篇关于我应该为HTTP标头使用什么字符编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆