且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 HTTP 标头发送非英语 unicode 字符串?

更新时间:2021-11-20 06:05:52

使用 HTTP Header 发送非英文字符串是不是 POSSIBLE 或 ALLOWED?

Is it not POSSIBLE or ALLOWED to send non-English string using HTTP Header?

根据 HTTP 标准,不可能将非 ISO-8859-1 字符直接放入 HTTP 标头中.这为您提供了 ASCII(英语"?)字符以及常见的西欧变音符号.

It's not possible as per HTTP standards to put non-ISO-8859-1 characters directly in an HTTP header. That gives you ASCII ("English"?) characters plus common Western European diacriticals.

但是在实践中,您甚至不能使用扩展的 ISO-8859-1 字符,因为服务器和浏览器在如何处理标头中的非 ASCII 字符方面存在分歧.Safari 使用 RFC2616 并将高字节视为 ISO-8859-1 字符;Mozilla 采用 UTF-16 代码单元低字节,类似但更奇怪;Opera 和 Chrome 从 UTF-8 解码;IE 使用本地系统代码页.

However in practice you can't even use the extended ISO-8859-1 characters, because servers and browsers don't agree on what to do with non-ASCII characters in headers. Safari takes RFC2616 at its word and treats high bytes as ISO-8859-1 characters; Mozilla takes UTF-16 code unit low bytes, which is similar but weirder; Opera and Chrome decode from UTF-8; IE uses the local system code page.

所以实际上,您可以在 HTTP 标头中放入的只是简单的 ASCII,没有控制代码.如果您想要更多,则必须提出一种编码方案(例如 UTF-8+base64).RFC2616 标准建议使用 RFC2047 编码字作为编码的标准形式,但鉴于 RFC2047 本身何时允许使用它们的定义,这没有任何意义,并且没有任何支持.

So in reality all you can put in an HTTP header is simple ASCII with no control codes. If you want anything more, you'll have to come up with an encoding scheme (eg UTF-8+base64). The RFC2616 standard suggests RFC2047 encoded-words as a standard form of encoding, but this makes no sense given the definitions of when they are allowable in RFC2047 itself, and nothing supports it.