POST和PUT HTTP REQUEST有什么区别? [英] What's the difference between a POST and a PUT HTTP REQUEST?

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

问题描述

他们似乎都在向身体内的服务器发送数据,那么是什么让他们与众不同?

They both seem to be sending data to the server inside the body, so what makes them different?

推荐答案

HTTP PUT:

PUT将文件或资源放在特定的URI上,并且恰好放在该URI上。如果该URI上已存在文件或资源,则PUT将替换该文件或资源。如果那里没有文件或资源,PUT会创建一个。 PUT是 idempotent ,但矛盾的是PUT响应不可缓存。

PUT puts a file or resource at a specific URI, and exactly at that URI. If there's already a file or resource at that URI, PUT replaces that file or resource. If there is no file or resource there, PUT creates one. PUT is idempotent, but paradoxically PUT responses are not cacheable.

PUT的HTTP 1.1 RFC位置

HTTP POST:

POST将数据发送到特定URI,并期望该URI处的资源处理该请求。此时,Web服务器可以确定如何处理指定资源的上下文中的数据。 POST方法不是 idempotent ,但POST响应<只要服务器设置了适当的Cache-Control和Expires标头,em> 就可以缓存。

POST sends data to a specific URI and expects the resource at that URI to handle the request. The web server at this point can determine what to do with the data in the context of the specified resource. The POST method is not idempotent, however POST responses are cacheable so long as the server sets the appropriate Cache-Control and Expires headers.

官方HTTP RFC指定POST为:

The official HTTP RFC specifies POST to be:


  • 现有资源的注释;

  • 向公告板,新闻组,邮件列表,$ b发送消息$ b或类似的文章组;

  • 向数据处理流程提供一个数据块,例如提交
    表格的结果;

  • 通过追加操作扩展数据库。

  • Annotation of existing resources;
  • Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles;
  • Providing a block of data, such as the result of submitting a form, to a data-handling process;
  • Extending a database through an append operation.

用于POST的HTTP 1.1 RFC位置

POST和PUT之间的差异:

RFC本身解释了核心差异:

The RFC itself explains the core difference:



之间的根本区别POST和PUT请求在
中反映了
Request-URI的不同含义。 POST请求中的URI
标识将
处理所包含实体的资源。
资源可能是接受数据的
进程,是某些其他
协议的网关,或者是
接受注释的单独实体。相反,PUT请求中的
URI标识随请求附带的
实体 -
用户代理知道什么URI是
预期,服务器绝不是
尝试将请求应用于某些
其他资源。如果服务器希望
请求应用于
不同的URI,它必须发送301(永久移动)响应;然后,用户代理可以自己决定是否重定向请求

The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. That resource might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed with the request -- the user agent knows what URI is intended and the server MUST NOT attempt to apply the request to some other resource. If the server desires that the request be applied to a different URI, it MUST send a 301 (Moved Permanently) response; the user agent MAY then make its own decision regarding whether or not to redirect the request.

使用正确的方法,无关:

REST ROA vs SOAP是指在使用HTTP REST ROA时,它鼓励正确使用HTTP谓词/方法。因此,例如,当您想要在该确切位置创建资源时,您将仅使用PUT。并且您永远不会使用GET来创建或修改资源。

One benefit of REST ROA vs SOAP is that when using HTTP REST ROA, it encourages the proper usage of the HTTP verbs/methods. So for example you would only use PUT when you want to create a resource at that exact location. And you would never use GET to create or modify a resource.

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

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