2026-03-02 12:44:43Accept 标头
语法
httpAccept:
Accept:
Accept: */*
// 多种类型,采用权重值语法区分
Accept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8
指令
一个单一且精确的媒体类型,例如 text/html。
没有指定子类型的媒体类型。例如,image/* 可对应 image/png、image/svg、image/gif 等多种图像类型。
*/*
任意媒体类型。
;q=(q 因子加权)
使用的值根据一个称为权重的相对质量价值来排序,表达了优先级顺序。
示例
使用默认的 Accept 请求标头
使用命令行工具(例如 curl 和 wget)发起的 HTTP 请求,其默认的 Accept 值为 */*:
httpGET / HTTP/1.1
Host: example.com
User-Agent: curl/8.7.1
Accept: */*
浏览器在进行页面导航请求时,通常会使用如下的 Accept 请求标头值:
httpGET /zh-CN/ HTTP/2
Host: developer.mozilla.org
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
…
在接收到文档后,对 Accept 示例页面中的图像发起的请求,其默认的 developer.mozilla.org 值如下所示:
httpAccept: image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5
为 JSON 响应配置 Accept 请求标头
在涉及 API 交互的系统中,通常会请求返回 application/json 格式的响应。以下是一个客户端明确请求 JSON 响应的 GET 请求示例:
httpGET /users/123 HTTP/1.1
Host: example.com
Authorization: Bearer abcd123
Accept: application/json
规范
Specification
HTTP Semantics# field.accept
浏览器兼容性
参见
HTTP 内容协商
Accept 默认值列表
列入 CORS 白名单的请求标头的限制
表示内容协商结果的消息标头:Content-Type
其他相似标头:TE、Accept-Encoding、Accept-Language
Help improve MDN
Was this page helpful to you?
Yes
No
Learn how to contribute
This page was last modified on 2025年10月23日 by MDN contributors.
View this page on GitHub • Report a problem with this content