带有 accept 的 HTTP 内容协商
HTTP Content Negotiation with accept
谁能帮我弄清楚 q 参数的数值代表什么。我知道这些值用于 select 您的偏好,但我不明白这些数字是如何使用的。例如,在下面的代码中,如果我使用 application/json;q=0.3,*/*,q=0.2
?
,我的偏好会保持不变吗?
headers.append('Accept', 'application/json;q=0.9,*/*;q=0.8');
这取决于服务器应用程序。
你的第一句话是 "I will accept json if you can guarantee 30% quality, but if not I can accept anything at 20% quality"。
你的第二个是 "I will accept json if you can guarantee 90% quality, but if not I can accept anything at 80% quality"。
但是,应用程序 可以 将其理解为 "provide json if you can, otherwise anything else"。
更多详情see this question。
谁能帮我弄清楚 q 参数的数值代表什么。我知道这些值用于 select 您的偏好,但我不明白这些数字是如何使用的。例如,在下面的代码中,如果我使用 application/json;q=0.3,*/*,q=0.2
?
headers.append('Accept', 'application/json;q=0.9,*/*;q=0.8');
这取决于服务器应用程序。
你的第一句话是 "I will accept json if you can guarantee 30% quality, but if not I can accept anything at 20% quality"。
你的第二个是 "I will accept json if you can guarantee 90% quality, but if not I can accept anything at 80% quality"。
但是,应用程序 可以 将其理解为 "provide json if you can, otherwise anything else"。
更多详情see this question。