Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. HTTP
  3. Reference
  4. Headers
  5. Accept

Accept header

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

The HTTPAcceptrequest andresponse header indicates which content types, expressed asMIME types, the sender is able to understand.In requests, the server usescontent negotiation to select one of the proposals and informs the client of the choice with theContent-Type response header.In responses, it provides information about which content types the server can understand in messages to the requested resource, so that the content type can be used in subsequent requests to the resource.

Browsers set required values for this header based on the context of the request.For example, a browser uses different values in a request when fetching a CSS stylesheet, image, video, or a script.

Header typeRequest header,Response header
Forbidden request headerNo
CORS-safelisted request header Yes*

* Values can't containCORS-unsafe request header bytes, including"():<>?@[\]{},, Delete0x7F, and control characters0x00 to0x19, except for Tab0x09.

Syntax

http
Accept: <media-type>/<MIME_subtype>Accept: <media-type>/*Accept: */*// Multiple types, weighted with the quality value syntaxAccept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8

Directives

<media-type>/<subtype>

A single, precisemedia type, liketext/html.

<media-type>/*

A media type without a subtype.For example,image/* corresponds toimage/png,image/svg,image/gif, and other image types.

*/*

Any media type.

;q= (q-factor weighting)

A value in order of preference expressed using a relativequality value called theweight.

Examples

Using default Accept request headers

HTTP requests made using command line tools such ascurl andwget use*/* as the defaultAccept value:

http
GET / HTTP/1.1Host: example.comUser-Agent: curl/8.7.1Accept: */*

Browser navigation typically has the followingAccept request header value:

http
GET /en-US/ HTTP/2Host: developer.mozilla.orgAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8…

After receiving the document, the defaultAccept values in requests for images on thedeveloper.mozilla.org example look like this:

http
Accept: image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5

Configuring Accept request headers for JSON responses

Systems that involve API interaction commonly requestapplication/json responses.Here's an example of aGET request where the client specifically requests a JSON response:

http
GET /users/123 HTTP/1.1Host: example.comAuthorization: Bearer abcd123Accept: application/json

Specifications

Specification
HTTP Semantics
# field.accept

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp