HTTP方法GET,POST,PUT和DELETE有什么区别 [英] What is difference between HTTP methods GET, POST, PUT and DELETE

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

问题描述

我正在开发REST WCF服务,从理论上讲,我知道何时选择该用途。

I am developing REST WCF service and As theoretically i know when to opt for what purpose.


  • GET 获取资源

  • PUT 更新

  • POST 插入

  • Delete 删除

  • GET to get the resource
  • PUT to update
  • POST to Insert
  • DELETE to delete

但是,如果我们不遵循上述规则,那么有什么缺点呢?假设插入一条我使用的记录 GET 方法?

But what is the disadvantage if we don't follow this above rule, suppose to insert a record i used GET method?

推荐答案

由于HTTP GET方法被指定为幂等,因此,通过规范可以将GET请求重新提交给假设它不会更改服务器上的任何内容。 HTTP POST并非如此,它可以通过规范来更改服务器上运行的应用程序的状态。

Because the HTTP GET method is specified as idempotent, a GET request, by specification, can be resubmitted with the assumption that it will not change anything on the server. This is not the case for a HTTP POST which by specification can change the status of the application running on the server.

因此,通过规范,可以执行HTTP GET N次翻页,而不必担心更改其状态。

So, by specification, one can perform an HTTP GET against a page N number of times without worrying of being changing its status.

不遵守规范可能会产生各种不良结果。例如,Web爬网程序遵循GET请求来索引站点,而不是POST。如果您允许HTTP GET请求对数据库进行更改,则可以轻松理解它可能具有的不希望的含义。

Not respecting the specification may have various undesired results. For example, Web crawlers follow through GET request to index a site, but not POST. If you allowed an HTTP GET request to make changes to the database, you can easily understand the undesired implication it can have.

重新指定规格就像遵守您之间的协议。服务或网站以及一系列不同的使用者,这些使用者可以是普通用户的浏览器,也可以是其他服务,例如网络搜寻器。

Respecting a specification is like respecting an agreement between your service or website and an array of different consumers which can be normal users' browsers but also other services like web crawlers.

您可以构建一个使用GET插入记录的网站,但是您还应该假设,使用该网站构建的任何东西都可以使用您的假设,

You could build a site that uses a GET to insert a record, but you should also expect that whatever is built around to consume your site is functioning with the assumption that you are respecting the agreement.

最后一个例子是,Web浏览器在用户尝试刷新HTTP POST请求访问的页面时警告用户,警告某些数据可能是重新提交。如果HTTP GET请求访问了该页面,则不会获得内置保护层的内置浏览器。

As a last example, web browsers warn users when they try to refresh a page that was reached by a HTTP POST request warning that some data might be resubmitted. You do not get that layer of protection built-in browsers if the page is reached by a HTTP GET request.

您可以在此处了解更多信息: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

You can read more here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

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

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