From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/http/headers/accept/index.html | 85 ++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 files/zh-cn/web/http/headers/accept/index.html (limited to 'files/zh-cn/web/http/headers/accept') diff --git a/files/zh-cn/web/http/headers/accept/index.html b/files/zh-cn/web/http/headers/accept/index.html new file mode 100644 index 0000000000..13e1fbaa34 --- /dev/null +++ b/files/zh-cn/web/http/headers/accept/index.html @@ -0,0 +1,85 @@ +--- +title: Accept +slug: Web/HTTP/Headers/Accept +translation_of: Web/HTTP/Headers/Accept +--- +
{{HTTPSidebar}}
+ +

Accept 请求头用来告知(服务器)客户端可以处理的内容类型,这种内容类型用MIME类型来表示。借助内容协商机制, 服务器可以从诸多备选项中选择一项进行应用,并使用 {{HTTPHeader("Content-Type")}} 应答头通知客户端它的选择。浏览器会基于请求的上下文来为这个请求头设置合适的值,比如获取一个CSS层叠样式表时值与获取图片、视频或脚本文件时的值是不同的。

+ + + + + + + + + + + + + + + + +
Header type{{Glossary("Request header")}}
{{Glossary("Forbidden header name")}}no
{{Glossary("Simple header", "CORS-safelisted request-header")}}yes
+ +

语法

+ +
Accept: <MIME_type>/<MIME_subtype>
+Accept: <MIME_type>/*
+Accept: */*
+
+// Multiple types, weighted with the {{glossary("quality values", "quality value")}} syntax:
+Accept: text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8
+ +

指令

+ +
+
<MIME_type>/<MIME_subtype>
+
单一精确的 MIME 类型, 例如text/html.
+
<MIME_type>/*
+
一类 MIME 类型, 但是没有指明子类。 image/* 可以用来指代 image/png, image/svg, image/gif 以及任何其他的图片类型。
+
*/*
+
任意类型的 MIME 类型
+
;q= (q因子权重)
+
值代表优先顺序,用相对质量价值表示,又称作权重。
+
+ +

示例

+ +
Accept: text/html
+
+Accept: image/*
+
+Accept: text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8
+
+ +

规范

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

浏览器兼容性

+ + + +

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

+ +

参见

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