简体   繁体   English

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

[英]Can HTTP PUT request have application/x-www-form-urlencoded as the Content-Type?

Is it valid to send form data in an HTTP PUT request?在 HTTP PUT 请求中发送表单数据是否有效? If you could point me to a spec then that would be great.如果您能指出我的规格,那就太好了。

I have gone through the HTTP 1.1 spec.我已经通过了 HTTP 1.1 规范。 But I did not find whether PUT requests can have form data or not.但我没有发现 PUT 请求是否可以有表单数据。

I am using Java for creating and accessing RESTful webservices.我正在使用 Java 来创建和访问 RESTful Web 服务。 POST supports application/x-www-form-urlencoded as the Content-Type. POST 支持application/x-www-form-urlencoded作为 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.从规范中,我了解到 POST 用于创建新资源(请求 URI 标识的资源的子资源),而 PUT 用于创建或更新资源。

But my doubt is whether PUT method also can have form data in it?但我的疑问是 PUT 方法是否也可以包含表单数据? 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.我在 HTTP 1.1 规范中找不到任何关于此的内容。

Yes you can use application/x-www-form-urlencoded with PUT.是的,您可以将 application/x-www-form-urlencoded 与 PUT 一起使用。 The HTTP spec does not limit what methods can be used with what media types. HTTP 规范不限制什么方法可以用于什么媒体类型。

The currently in-progress Httpbis spec has a significantly expanded discussion of PUT http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-14#page-18目前正在进行的 Httpbis 规范对 PUT http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-14#page-18进行了显着扩展的讨论

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.由于PUT 方法用于在提供的 URI 下存储封闭的实体,并且Content-Type header 字段实体 header 字段,因此在 PUFT 请求中使用Content-Type Z099FB995346F33C749F6E40E3Z 字段是合法的。

Now the remaining question is whether the receiving server can handle such request and Content-Type information appropriately.现在剩下的问题是接收服务器是否可以适当地处理此类请求和Content-Type信息。 In worst case it can't handle the Content-Type header field and returns a 501 response:在最坏的情况下,它无法处理Content-Type header 字段并返回 501 响应:

The recipient of the entity MUST NOT ignore any Content-* (eg Content-Range ) headers that it does not understand or implement and MUST return a 501 (Not Implemented) response in such cases.实体的接收者不能忽略任何它不理解或不实现的Content-* (例如Content-Range )标头,并且在这种情况下必须返回 501(未实现)响应。

Here is the HTTP spec from the wc3这是 wc3 中的 HTTP 规范

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

Additionally, here are the pages for Content-Type此外,这里是 Content-Type 的页面

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

and PUT和放

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 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如果您需要有关 HTTP PUT 的特定语言的帮助,请使用具体信息更新您的问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在WCF ReSTful服务中,POST或PUT请求的Content-Type是否需要为“ application / x-www-form-urlencoded”? - Does the Content-Type of a POST or PUT request need to be 'application/x-www-form-urlencoded' in a WCF ReSTful service? 使用$ http POST Content-Type应用程序/ x-www-form-urlencoded访问API - Accessing API with $http POST Content-Type application/x-www-form-urlencoded 如何发送内容类型为“ application / x-www-form-urlencoded”的POST请求 - How to send a POST request with Content-Type “application/x-www-form-urlencoded” C# HttpClient REST 请求使用 Content-Type: application/x-www-form-urlencoded - C# HttpClient REST request using Content-Type: application/x-www-form-urlencoded 无法根据内容类型在请求后创建模拟:application / x-www-form-urlencoded - Unable to create mocks on post request with content-type : application/x-www-form-urlencoded 如何在包含application / x-www-form-urlencoded数据的perl中发出HTTP PUT请求? - How can I make a HTTP PUT request in perl that contains application/x-www-form-urlencoded data? 内容类型为 application/x-www-form-urlencoded 的 Http Post 请求在 Spring 中不起作用 - Http Post request with content type application/x-www-form-urlencoded not working in Spring 如何编写控制器类以允许内容类型:application / json和application / x-www-form-urlencoded - How to write controller class to allow content-type: application/json and application/x-www-form-urlencoded 如何在 Informatica 云中为标题“Content-Type: application/x-www-form-urlencoded”生成 swagger 文件? - How to generate a swagger file for the header "Content-Type: application/x-www-form-urlencoded" in Informatica cloud? 在REST Web服务中遇到Content-Type“应用程序/ x-www-form-urlencoded”的困扰 - Struggled with Content-Type “application/x-www-form-urlencoded” in REST webservices
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM