http - 响应不带位置的 HTTP POST 请求

标签 http

成功的 HTTP POST 请求后,客户端可以跟踪响应 header 中包含的 URI,名为 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 是 与有效请求URI相同,该信息可以省略 (例如,在响应 PUT 请求的情况下)

因此您可以省略“位置” header 。

关于http - 响应不带位置的 HTTP POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29202992/

相关文章:

asp.net - 有没有办法在用户离开页面时使用 ASP.NET 始终运行一些服务器端代码?

c++ - C++ 中的 HTTP 代理服务器

php - SOAP:HTTP 错误请求

android - 谷歌网址缩短器 API 错误(403 禁止)[更新]

java - 如何解析多部分/表单数据?

ruby-on-rails - 并发 Net::HTTP.get 到同一个域

angularjs - 将 $http 响应对象保存为 $scope 变量

android - Http Get 请求返回 html?

node.js - 在 Node.js 中发送多个 HTTP 请求 : Not receiving any responses or timeouts

multithreading - ColdFusion/Railo 组件线程化 http 请求