响应没有位置的 HTTP POST 请求
Respond to HTTP POST request without Location
成功的 HTTP POST
请求后,客户端可以遵循响应中包含的 URI header,名为 Location
.
我想知道是否允许不提供此 header Location
,例如在单例资源上,例如:
POST /users/42/profile
...因为在这个请求之后,如果成功(状态码201
),客户端已经知道创建资源的位置,所以再一次重定向它是没有用的到当前 URI。
在这种情况下,Location
响应 header 是可选的吗?可以不提供给HTTP客户端吗?
根据 HTTP spec
14.30 Location
The Location response-header field is used to redirect the recipient
to a location other than the Request-URI for completion of the request
or identification of a new resource. For 201 (Created) responses, the
Location is that of the new resource which was created by the request.
新创建的资源通常链接到响应
有效载荷,最相关的 URI 也被携带在
位置 header 字段。如果新创建的资源的 URI 是
与Effective Request URI相同,该信息可以省略
(例如,在响应 PUT 请求的情况下)
所以你可以省略 "Location" header.
成功的 HTTP POST
请求后,客户端可以遵循响应中包含的 URI header,名为 Location
.
我想知道是否允许不提供此 header Location
,例如在单例资源上,例如:
POST /users/42/profile
...因为在这个请求之后,如果成功(状态码201
),客户端已经知道创建资源的位置,所以再一次重定向它是没有用的到当前 URI。
在这种情况下,Location
响应 header 是可选的吗?可以不提供给HTTP客户端吗?
根据 HTTP spec
14.30 Location
The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource. For 201 (Created) responses, the Location is that of the new resource which was created by the request.
新创建的资源通常链接到响应 有效载荷,最相关的 URI 也被携带在 位置 header 字段。如果新创建的资源的 URI 是 与Effective Request URI相同,该信息可以省略 (例如,在响应 PUT 请求的情况下)
所以你可以省略 "Location" header.