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
指令
示例
Accept: text/html Accept: image/* Accept: text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8
规范
Specification | Title |
---|---|
RFC 7231, section 5.3.2: Accept | Hypertext Transfer Protocol (HTTP/1.1): Semantics and Context |
浏览器兼容性
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
参见
- HTTP 内容协商
- 表示内容协商结果的消息头:
Content-Type
- 其他相似消息头:
TE
,Accept-Encoding
,Accept-Charset
,Accept-Language