HTTP 中的 POST 和 PUT 有什麼區別? - What is the difference between POST and PUT in HTTP?

問題:

According to RFC 2616, § 9.5 , POST is used to create a resource:根據RFC 2616, § 9.5POST用於創建資源:

The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST 方法用於請求源服務器接受請求中包含的實體作爲請求行中的請求 URI 標識的資源的新從屬。

According to RFC 2616, § 9.6 , PUT is used to create or replace a resource:根據RFC 2616, § 9.6PUT用於創建或替換資源:

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. PUT 方法請求將封閉的實體存儲在提供的 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.如果請求 URI 引用了一個已經存在的資源,則包含的實體應該被視爲駐留在源服務器上的實體的修改版本。 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.如果 Request-URI 不指向現有資源,並且該 URI 能夠被請求的用戶代理定義爲新資源,則源服務器可以使用該 URI 創建資源。

So which HTTP method should be used to create a resource?那麼應該使用哪種 HTTP 方法來創建資源呢? Or should both be supported?或者兩者都應該支持?


解決方案:

參考一: https://stackoom.com/question/2e0b
參考二: What is the difference between POST and PUT in HTTP?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章