300 Multiple Choices

HTTP 300 多個選擇 重定向響應狀態碼錶示請求有多個可能的響應。使用者代理或使用者應該選擇其中一個。

注意:代理驅動的內容協商中,當伺服器有多個資源變體時,客戶端和伺服器會協同決定給定資源的最佳變體。大多數客戶端缺乏自動從響應中選擇的方法,並且額外的往返會減慢客戶端-伺服器互動。伺服器驅動的內容協商更為常見,其中伺服器根據請求頭(Accept-LanguageAccept 等)為客戶端選擇最合適的資源。

伺服器應在響應中包含內容,其中包含使用者或使用者代理可以選擇的資源元資料和 URI 列表。內容的格式是特定於實現的,但應該易於使用者代理解析(例如 HTML 或 JSON)。

如果伺服器有一個客戶端應該請求的首選選擇,它可以將其包含在 Location 頭中。

狀態

http
300 Multiple Choices

示例

帶有資源列表的 300 響應

以下示例演示了透明內容協商的請求-響應交換。Apache 伺服器提供在型別對映中定義的資源的多個變體;index.html.en 用於英文資源,index.html.fr 用於法文版本

http
URI: index.html.en
Content-Language: en

URI: index.html.fr
Content-Language: fr

Negotiate: trans 請求頭表示客戶端希望使用 TCN 來選擇資源。這種機制的瀏覽器支援不佳意味著必須使用像 curl 這樣的使用者代理

bash
 curl -v -H "Negotiate: trans" https:///index

這將產生以下請求

http
GET /index HTTP/1.1
Host: localhost
User-Agent: curl/8.7.1
Accept: */*
Negotiate: trans

我們收到一個 300 響應,其中包含請求資源的不同表示的詳細資訊

http
HTTP/1.1 300 Multiple Choices
Date: Fri, 30 Aug 2024 09:21:48 GMT
Server: Apache/2.4.59 (Unix)
Alternates: {"index.html.en" 1 {type text/html} {language en} {length 48}}, {"index.html.fr" 1 {type text/html} {language fr} {length 45}}
Vary: negotiate,accept-language
TCN: list
Content-Length: 419
Content-Type: text/html; charset=iso-8859-1

<html><head>
<title>300 Multiple Choices</title>
</head><body>
<h1>Multiple Choices</h1>
Available variants:
<ul>
<li><a href="index.html.en">index.html.en</a> , type text/html, language en</li>
<li><a href="index.html.fr">index.html.fr</a> , type text/html, language fr</li>
</ul>
</body></html>

規範

規範
HTTP 語義
# status.300

另見