且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HTTP方法GET,POST,PUT和DELETE有什么区别

更新时间:2022-04-29 01:06:31

由于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