PUT和DELETE HTTP请求方法的用处是什么? [英] What is the usefulness of PUT and DELETE HTTP request methods?

查看:234
本文介绍了PUT和DELETE HTTP请求方法的用处是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多相关内容,但无法就此主题得出结论。

I have read a lot stuff about this but not able to get the conclusion on this topic.

但我从未使用过PUT或DELETE HTTP Request方法。我倾向于在系统(我的应用程序或网站)的统计数据可能不受影响(如产品列表)时使用GET,并在受影响时使用POST(下订单)。是不够还是我错过了什么?

But I've never used PUT or DELETE HTTP Request methods. My tendency is to use GET when stat of the system(my application or website) may not be affected (like product listing) and to use POST when it is affected(order placed). Isn't it sufficient or am I missing something ?

推荐答案

DELETE用于删除请求资源:

DELETE is for deleting the request resource:


DELETE方法请求源服务器删除Request-URI标识的资源。可以通过源服务器上的人为干预(或其他方式)来覆盖此方法。即使从原始服务器返回的状态代码表明操作已成功完成,也无法保证客户端已执行该操作...

The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the operation has been carried out, even if the status code returned from the origin server indicates that the action has been completed successfully …

PUT用于在服务器上放置或更新资源:

PUT is for putting or updating a resource on the server:


PUT方法请求将所包含的实体存储在提供的Request-URI。如果Request-URI引用已经存在的资源,则封闭的实体应该被视为驻留在源服务器上的实体的修改版本。如果Request-URI未指向现有资源,并且该URI能够被请求用户代理定义为新资源,则源服务器可以使用该URI创建资源...

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI …

如需完整规格,请访问:

For the full specification visit:

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

由于当前的浏览器不支持HTML表单中除POST和GET之外的任何其他动词,您通常无法使用HTTP来充分利用它们(您仍然可以通过JavaScript劫持他们的提交)。 HTML表单中缺少对这些方法的支持导致URI包含动词,例如

Since current browsers unfortunately do not support any other verbs than POST and GET in HTML forms, you usually cannot utilize HTTP to it's full extent with them (you can still hijack their submission via JavaScript though). The absence of support for these methods in HTML forms led to URIs containing verbs, like for instance

POST http://example.com/order/1/delete

甚至更差

POST http://example.com/deleteOrder/id/1

通过HTTP有效地隧道化CRUD语义。但动词从未打算成为URI的一部分。相反,HTTP已经通过HTTP方法向CRUD资源(例如订单)提供机制和语义。 HTTP是一种协议而不仅仅是一些数据隧道服务。

effectively tunneling CRUD semantics over HTTP. But verbs were never meant to be part of the URI. Instead HTTP already provides the mechanism and semantics to CRUD a Resource (e.g. an order) through the HTTP methods. HTTP is a protocol and not just some data tunneling service.

因此,要删除网络服务器上的资源,您需要调用

So to delete a Resource on the webserver, you'd call

DELETE http://example.com/order/1

并更新它你打电话

PUT http://example.com/order/1

并在PUT正文中提供更新的资源表示,供网络服务器申请。

and provide the updated Resource Representation in the PUT body for the webserver to apply then.

因此,如果您正在为 REST API <构建某种客户端/ a>,您可能会发送PUT和DELETE请求。这可以是在浏览器内构建的客户端,例如通过JavaScript发送请求或者它可能是服务器上运行的某些工具等。

So, if you are building some sort of client for a REST API, you will likely make it send PUT and DELETE requests. This could be a client built inside a browser, e.g. sending requests via JavaScript or it could be some tool running on a server, etc.

有关更多详细信息,请访问:

For some more details visit:

  • http://martinfowler.com/articles/richardsonMaturityModel.html
  • Are the PUT, DELETE, HEAD, etc methods available in most web browsers?
  • Why are there no PUT and DELETE methods in HTML forms
  • Should PUT and DELETE be used in forms?
  • http://amundsen.com/examples/put-delete-forms/
  • http://www.quora.com/HTTP/Why-are-PUT-and-DELETE-no-longer-supported-in-HTML5-forms

这篇关于PUT和DELETE HTTP请求方法的用处是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆