HTTP PUT 请求可以将 application/x-www-form-urlencoded 作为 Content-Type 吗?

发布于 2024-11-14 23:51:58 字数 356 浏览 5 评论 0 原文

在 HTTP PUT 请求中发送表单数据是否有效?如果您能给我指出一个规格,那就太好了。

我已经阅读了 HTTP 1.1 规范。但我没有发现PUT请求是否可以有表单数据。

我正在使用 Java 创建和访问 RESTful Web 服务。 POST 支持 application/x-www-form-urlencoded 作为 Content-Type。

从规范中,我了解到 POST 用于创建新资源(请求 URI 标识的资源的子资源),而 PUT 用于创建或更新资源。

但我的疑问是 PUT 方法中是否也可以有表单数据?我试图根据规范找出它是否可以。我在 HTTP 1.1 规范中找不到任何与此相关的内容。

Is it valid to send form data in an HTTP PUT request? If you could point me to a spec then that would be great.

I have gone through the HTTP 1.1 spec. But I did not find whether PUT requests can have form data or not.

I am using Java for creating and accessing RESTful webservices. POST supports application/x-www-form-urlencoded as the Content-Type.

From the specification, I understand that POST is for creating a new resource (a subresource to the resource identified by the request URI) and PUT is for create or update a resource.

But my doubt is whether PUT method also can have form data in it? I trying to find out whether it is fine according to the spec. And I can't find anything about this in the HTTP 1.1 spec.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

2024-11-21 23:51:58

是的,您可以将 application/x-www-form-urlencoded 与 PUT 一起使用。 HTTP 规范不限制什么方法可以用于什么媒体类型。

当前正在进行的 Httpbis 规范对 PUT https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-p2-semantics-14#page-18

Yes you can use application/x-www-form-urlencoded with PUT. The HTTP spec does not limit what methods can be used with what media types.

The currently in-progress Httpbis spec has a significantly expanded discussion of PUT https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-p2-semantics-14#page-18

苍风燃霜 2024-11-21 23:51:58

由于 PUT 方法 用于存储所附的 实体Content-Type 标头字段实体标头字段,在 PUT 请求中使用 Content-Type 标头字段是合法的。

现在剩下的问题是接收服务器是否可以适当地处理此类请求和Content-Type信息。在最坏的情况下,它无法处理 Content-Type 标头字段并返回 501 响应:

实体的接收者不得忽略任何Content-*
(例如 Content-Range)它不理解或实现的标头
并且在这种情况下必须返回 501(未实现)响应。

Since the PUT method is used to store the enclosed entity under the supplied URI and the Content-Type header field is an entity header field, it is legitimate to use a Content-Type header field in a PUT request.

Now the remaining question is whether the receiving server can handle such request and Content-Type information appropriately. In worst case it can’t handle the Content-Type header field and returns a 501 response:

The recipient of the entity MUST NOT ignore any Content-*
(e.g. Content-Range) headers that it does not understand or implement
and MUST return a 501 (Not Implemented) response in such cases.

煮酒 2024-11-21 23:51:58

这是 wc3

http://www.w3.org/Protocols/rfc2616 的 HTTP 规范/rfc2616.html

的页面

另外,这里是 Content-Type http://www.w3.org/Protocols/rfc2616/rfc2616-sec14 .html#sec14.17

和 PUT

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9 .html#sec9.6

如果您需要有关 HTTP PUT 的特定语言的帮助,请使用具体信息更新您的问题

Here is the HTTP spec from the wc3

http://www.w3.org/Protocols/rfc2616/rfc2616.html

Additionally, here are the pages for Content-Type

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17

and PUT

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6

If there is a specific language you want help with in regard to your HTTP PUT, please update your question with the specifics

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文