表单中应该使用 PUT 和 DELETE 吗?

假设我的 Web 应用程序在服务器端完全支持 PUT 和 DELETE,我应该使用它们吗?

基本上,我的问题是有多少浏览器支持这一点:

<form method="PUT">

或者

<form method="DELETE">

除了与 REST 兼容之外,使用这两种 HTTP 方法还有其他好处吗?(假设这两种方法的替代品是常用的 POST)

118213 次浏览

No, GET & POST are the only valid HTTP method values for the method attribute. See the HTML spec for more information.

I believe you can use them in AJAX requests, though.

Your question involves two closely related but separate standards, HTTP and HTML. The PUT and DELETE methods are part of HTTP. In HTTP they have obvious use in RESTful interfaces, and other services which build on HTTP such as Webdav.

HTML up to version 4 only defines the use of POST and GET for forms. HTML5 at this time appears as though it may support the further methods. [note, support is not included in the current w3 draft]

Any current browser support (I'm not directly aware of any) will be very limited and only really useful as an experiment at the bleeding edge.

GET, POST, PUT and DELETE (there are others) are a part of the HTTP standard, but you are limited to GET and POST in HTML forms at this time.

As Andrew mentioned, you can use PUT and DELETE in AJAX requests; however, this only works in some browsers (see http://api.jquery.com/jQuery.ajax/).

As of September 2022, latest HTML specs and drafts still don't have support for methods other than GET and POST by default. If you don't use a method middleware, you are stuck with these two options. (method attribute can also have 'dialog' as a value, but it is irrelevant since it is not directly related to HTTP methods.)

https://html.spec.whatwg.org/#attr-fs-method