Accept
Accept
请求头用来告知(服务器)客户端可以处理的内容类型,这种内容类型用MIME 类型来表示。借助内容协商机制, 服务器可以从诸多备选项中选择一项进行应用,并使用 Content-Type
应答头通知客户端它的选择。浏览器会基于请求的上下文来为这个请求头设置合适的值,比如获取一个 CSS 层叠样式表时值与获取图片、视频或脚本文件时的值是不同的。
Header type | Request header |
---|---|
Forbidden header name | no |
CORS-safelisted request-header | yes |
语法
Accept: <MIME_type>/<MIME_subtype> Accept: <MIME_type>/* Accept: */* // Multiple types, weighted with the 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
规范
Specification |
---|
HTTP Semantics # field.accept |
浏览器兼容性
BCD tables only load in the browser
参见
- HTTP 内容协商
- 表示内容协商结果的消息头:
Content-Type
- 其他相似消息头:
TE
、Accept-Encoding
、Accept-Charset
、Accept-Language