What is the purpose of the “q” values in the HTTP “Accept” request header?

后端 未结 4 609
情歌与酒
情歌与酒 2020-12-24 06:46

I have made a http request using Firefox.Now the request header shows the following:

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
         


        
相关标签:
4条回答
  • 2020-12-24 07:22

    The Q value is aways a number from zero to one and it represents the relative quality value. The default Q value is 1.0.

    So something with Q value 0.9 is just slightly more preferred than something with Q value of 0.6.

    0 讨论(0)
  • 2020-12-24 07:31

    The Accept header list is first split at , then at ; for additional parameters per entry. So, the list in your example splits down to text/html, application/xhtml+xml, application/xml;q=0.9 and */*;q=0.8. The q= parameter on each entry indicates to the server the degree of preference for that media-type. It defaults to its maximum value of 1, if it is missing (like in the first 2 entries). The last entry of */*;q=0.8 indicates to the server, that eventually any content-type would be acceptable but would be less preferable than the others listed. Otherwise, the server might decide to send no content at all, because the client would not "accept" it anyway.

    0 讨论(0)
  • 2020-12-24 07:35

    Each media-range MAY be followed by one or more accept-params, beginning with the "q" parameter for indicating a relative quality factor. The first "q" parameter (if any) separates the media-range parameter(s) from the accept-params. Quality factors allow the user or user agent to indicate the relative degree of preference for that media-range, using the qvalue scale from 0 to 1. The default value is q=1

    The information is available here

    A nice explanation can be found here as well.

    0 讨论(0)
  • 2020-12-24 07:35

    To add to @Robin479's correct answer, the accept header in the question is equivalent to,

    Accept:
    text/html;q=1,
    application/xhtml+xml;q=1,
    application/xml;q=0.9,
    */*;q=0.8

    NOTE: The new line characters are just for better readability.

    0 讨论(0)
提交回复
热议问题