问题:
According to the HTTP/1.1 Spec: 根据HTTP / 1.1规范:
The
POSTmethod is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by theRequest-URIin theRequest-LinePOST方法用于请求源服务器接受请求中包含的实体作为Request-LineRequest-URI标识的资源的新下属
In other words, POST is used to create . 换句话说, POST用于创建 。
The
PUTmethod requests that the enclosed entity be stored under the suppliedRequest-URI.PUT方法请求将封闭的实体存储在提供的Request-URI。 If theRequest-URIrefers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. 如果Request-URI引用了已经存在的资源,则应将封闭的实体视为驻留在原始服务器上的实体的修改版本。 If theRequest-URIdoes 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." 如果Request-URI没有指向现有资源,并且请求用户代理能够将该URI定义为新资源,则原始服务器可以使用该URI创建资源。”
That is, PUT is used to create or update . 也就是说, PUT用于创建或更新 。
So, which one should be used to create a resource? 那么,应该使用哪一个来创建资源? Or one needs to support both? 还是需要同时支持两者?
解决方案:
参考一: https://stackoom.com/question/2e0b/REST中的PUT与POST参考二: https://oldbug.net/q/2e0b/PUT-vs-POST-in-REST
来源:oschina
链接:https://my.oschina.net/u/4428122/blog/4449063