根据HTTP规范:
如果在原始服务器上创建了资源,则响应应为SHOULD 为201(已创建)并包含一个实体,它描述了请求的状态,并引用了新的资源,以及一个Location头(参见第14.30节) )。
If a resource has been created on the origin server, the response SHOULD be 201 (Created) and contain an entity which describes the status of the request and refers to the new resource, and a Location header (see section 14.30).
这是否意味着POST请求应始终在Location头中发送没有响应正文的重定向URI?
Does this mean that POST request should always send redirect URI in Location header with no response body?
推荐答案指定响应主体和同时使用Location标头是完全可以接受的。当使用带有201响应的Location标头时,您不会重定向客户端,您只是告诉它将来可以在哪里找到该资源。
It is perfectly acceptable to specify a response body and use the Location header at the same time. When using the Location header with a 201 response, you're not redirecting the client, you're just telling it where it can find the resource in future.
仅重定向适用于3xx回复。
Redirects only apply to 3xx responses.
W3C docs for this 进一步解释,虽然文本实际上很模糊:
The W3C docs for this explain further, though the text is actually quite ambiguous:
位置响应-header字段用于将收件人重定向到Request-URI以外的位置,以完成请求或标识新资源。对于201(已创建)响应,位置是由请求创建的新资源的位置。对于3xx响应,位置应该应该指示服务器自动重定向到资源的首选URI。
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. For 3xx responses, the location SHOULD indicate the server's preferred URI for automatic redirection to the resource.
我读到这就是说.. .redirect ...或... identify [y] ... new resource,但它并不是一个简单的英语句子。
I read that as saying "...redirect... or... identif[y]... new resource", but it's not exactly a plain English sentence.
更多推荐
是否允许HTTP POST请求发送回响应正文?
发布评论