简体   繁体   中英

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? 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.

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 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.

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-* (eg Content-Range ) headers that it does not understand or implement and MUST return a 501 (Not Implemented) response in such cases.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM