From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/http/headers/accept-charset/index.html | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 files/zh-cn/web/http/headers/accept-charset/index.html (limited to 'files/zh-cn/web/http/headers/accept-charset/index.html') diff --git a/files/zh-cn/web/http/headers/accept-charset/index.html b/files/zh-cn/web/http/headers/accept-charset/index.html new file mode 100644 index 0000000000..151a09575d --- /dev/null +++ b/files/zh-cn/web/http/headers/accept-charset/index.html @@ -0,0 +1,90 @@ +--- +title: Accept-Charset +slug: Web/HTTP/Headers/Accept-Charset +tags: + - HTTP + - HTTP Header + - POST + - Request header + - 内容协商 + - 请求头 +translation_of: Web/HTTP/Headers/Accept-Charset +--- +
{{HTTPSidebar}}
+ +

Accept-Charset 请求头用来告知(服务器)客户端可以处理的字符集类型。 借助内容协商机制,服务器可以从诸多备选项中选择一项进行应用, 并使用{{HTTPHeader("Content-Type")}} 应答头通知客户端它的选择。浏览器通常不会设置此项值,因为每种内容类型的默认值通常都是正确的,但是发送它会更有利于识别。

+ +

如果服务器不能提供任何可以匹配的字符集的版本,那么理论上来说应该返回一个 {{HTTPStatus("406")}} (Not Acceptable,不被接受)的错误码。但是为了更好的用户体验,这种方法很少采用,取而代之的是将其忽略。

+ +
+

在早期版本的HTTP/1.1协议中,规定了一个默认的字符集(ISO-8859-1)。但是现在情况不同了,目前每一种内容类型都有自己的默认字符集。

+
+ + + + + + + + + + + + +
Header type{{Glossary("Request header")}}
{{Glossary("Forbidden header name")}}yes
+ +

句法

+ +
Accept-Charset: <charset>
+
+// Multiple types, weighted with the {{glossary("quality values", "quality value")}} syntax:
+Accept-Charset: utf-8, iso-8859-1;q=0.5
+ +

指令

+ +
+
<charset>
+
诸如 utf-8 或 iso-8859-15的字符集。
+
*
+
在这个消息头中未提及的任意其他字符集;'*' 用来表示通配符。
+
;q= (q-factor weighting)
+
值代表优先顺序,用相对质量价值表示,又称为权重。
+
+ +

例子

+ +
Accept-Charset: iso-8859-1
+
+Accept-Charset: utf-8, iso-8859-1;q=0.5
+
+Accept-Charset: utf-8, iso-8859-1;q=0.5, *;q=0.1
+
+ +

规范

+ + + + + + + + + + + + +
SpecificationTitle
{{RFC("7231", "Accept-Charset", "5.3.3")}}Hypertext Transfer Protocol (HTTP/1.1): Semantics and Context
+ +

浏览器兼容性

+ + + +

{{Compat("http.headers.Accept-Charset")}}

+ +

参见

+ + -- cgit v1.2.3-54-g00ecf