是否允许HTTP POST请求发送回响应正文? [英] Is HTTP POST request allowed to send back a response body?

查看:344
本文介绍了是否允许HTTP POST请求发送回响应正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据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请求发送回响应正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆