使用非英语字符的HTTP标头 [英] HTTP Header using non-english character

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

问题描述

我正在使用高级REST客户端应用程序(Chrome插件)来使用HTTP标头执行身份验证,并且可以正常工作.

I am using Advanced REST Client Application (Chrome plugin) to perform authentication using HTTP header and it works.

X-Username: member
X-Password: abc123

但是,当我尝试使用非英语用户名时

However when I tried to use non english username

X-Username: 阿里巴巴
X-Password: abc123

我收到以下错误

Unable set request header: X-Username: 阿里巴巴

如何设置请求标头以使用中文字符(如果可能)?

How can I set a request header to use Chinese character if it's possible ?

推荐答案

根据规范

According to the specification RFC 7230 (HTTP 1.1):

从历史上看,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.

也就是说,有一个用于凭证的标准HTTP标头,即 Authorization .您可以使用基本身份验证,其内容将使用base64进行编码:

That said, there is a standard HTTP header for credentials, the Authorization one. You can use the basic authentication and its content would be encoded with base64:

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

Basic 之后的值是字符串 username:password 的编码值.有关此类机制的更多详细信息,请参见以下链接: https://en.wikipedia.org/wiki/Basic_access_authentication.

The value after Basic is the encoded value of the string username:password. For more details about such mechanism, see this link: https://en.wikipedia.org/wiki/Basic_access_authentication.

另请参阅此答案以了解更多详细信息:应使用哪种编码我用于HTTP基本身份验证吗?.

See also this answer for more details: What encoding should I use for HTTP Basic Authentication?.

希望它对您有帮助,蒂埃里

Hope it helps you, Thierry

这篇关于使用非英语字符的HTTP标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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