接受和接受 - Charset - 哪个优越? [英] Accept and Accept-Charset - Which is superior?

查看:108
本文介绍了接受和接受 - Charset - 哪个优越?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTTP中,您可以在请求中指定您的客户端可以使用 accept 标头接受响应中的特定内容,其值为 application / XML 。内容类型规范允许您在内容类型中包含参数,例如 charset = utf-8 ,表示您可以接受具有指定字符集的内容。

In HTTP you can specify in a request that your client can accept specific content in responses using the accept header, with values such as application/xml. The content type specification allows you to include parameters in the content type, such as charset=utf-8, indicating that you can accept content with a specified character set.

还有 accept-charset 标头,它指定客户接受的字符编码。

There is also the accept-charset header, which specifies the character encodings which are accepted by the client.

如果指定了两个标头并且 accept 标头包含带有charset参数的内容类型,则应将其视为上级标头服务器?

If both headers are specified and the accept header contains content types with the charset parameter, which should be considered the superior header by the server?

例如:

Accept: application/xml; q=1,
        text/plain; charset=ISO-8859-1; q=0.8
Accept-Charset: UTF-8

我发送了一些例子使用Fiddler向各种服务器请求测试他们的回复方式:

I've sent a few example requests to various servers using Fiddler to test how they respond:

示例

W3

请求

GET http://www.w3.org/ HTTP/1.1
Host: www.w3.org
Accept: text/html;charset=UTF-8
Accept-Charset: ISO-8859-1

回复

Content-Type: text/html; charset=utf-8

Google

请求

GET http://www.google.co.uk/ HTTP/1.1
Host: www.google.co.uk
Accept: text/html;charset=UTF-8
Accept-Charset: ISO-8859-1

回复

Content-Type: text/html; charset=ISO-8859-1

StackOverflow

请求

GET http://stackoverflow.com/ HTTP/1.1
Host: stackoverflow.com
Accept: text/html;charset=UTF-8
Accept-Charset: ISO-8859-1

回复

Content-Type: text/html; charset=utf-8

Microsoft

请求

GET http://www.microsoft.com/ HTTP/1.1
Host: www.microsoft.com
Accept: text/html;charset=UTF-8
Accept-Charset: ISO-8859-1

回复

Content-Type: text/html

对预期的行为似乎没有任何共识。我试图让人感到惊讶。

There doesn't seem to be any consensus around what the expected behaviour is. I am trying to look surprised.

推荐答案

你可以在中设置媒体类型 header,该媒体类型的 charset 参数定义未在 RFC 2616 (但不禁止这样做)。

Altough you can set media type in Accept header, the charset parameter definition for that media type is not defined anywhere in RFC 2616 (but it is not forbidden, though).

因此,如果要实现符合HTTP 1.1的服务器,首先应查找 Accept-charset 标头,然后在接受标题搜索您自己的参数。

Therefore if you are going to implement a HTTP 1.1 compliant server, you shall first look for Accept-charset header, and then search for your own parameters at Accept header.

这篇关于接受和接受 - Charset - 哪个优越?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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