300 Multiple Choices
HTTP 300 多个选择
重定向响应状态码表示请求有多个可能的响应。用户代理或用户应该选择其中一个。
注意:在代理驱动的内容协商中,当服务器有多个资源变体时,客户端和服务器会协同决定给定资源的最佳变体。大多数客户端缺乏自动从响应中选择的方法,并且额外的往返会减慢客户端-服务器交互。服务器驱动的内容协商更为常见,其中服务器根据请求头(Accept-Language
、Accept
等)为客户端选择最合适的资源。
服务器应在响应中包含内容,其中包含用户或用户代理可以选择的资源元数据和 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 |