--- title: Accept slug: Web/HTTP/Headers/Accept translation_of: Web/HTTP/Headers/Accept ---
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>
text/html
.<MIME_type>/*
image/*
可以用来指代 image/png
, image/svg
, image/gif
以及任何其他的图片类型。*/*
;q=
(q因子权重)Accept: text/html Accept: image/* Accept: text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8
Specification | Title |
---|---|
{{RFC("7231", "Accept", "5.3.2")}} | Hypertext Transfer Protocol (HTTP/1.1): Semantics and Context |
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.
{{Compat("http.headers.Accept")}}