它们似乎都在向身体内部的服务器发送数据,那么它们有什么不同呢?


当前回答

GET: Retrieves data from the server. Should have no other effect. PUT: Replaces target resource with the request payload. Can be used to update or create a new resource. PATCH: Similar to PUT, but used to update only certain fields within an existing resource. POST: Performs resource-specific processing on the payload. Can be used for different actions including creating a new resource, uploading a file, or submitting a web form. DELETE: Removes data from the server. TRACE: Provides a way to test what the server receives. It simply returns what was sent. OPTIONS: Allows a client to get information about the request methods supported by a service. The relevant response header is Allow with supported methods. Also used in CORS as preflight request to inform the server about actual the request method and ask about custom headers. HEAD: Returns only the response headers. CONNECT: Used by the browser when it knows it talks to a proxy and the final URI begins with https://. The intent of CONNECT is to allow end-to-end encrypted TLS sessions, so the data is unreadable to a proxy.

其他回答

PUT是一种将内容“上载”到特定URI或覆盖该URI中已有内容的方法。

另一方面,POST是提交与给定URI相关的数据的一种方式。

参考HTTP RFC

POST和PUT之间的区别在于PUT是幂等的,这意味着多次调用相同的PUT请求总是会产生相同的结果(没有副作用),而另一方面,重复调用POST请求可能会产生多次创建相同资源的(额外的)副作用。

GET:使用GET的请求只检索数据,也就是说它请求指定资源的表示

POST:向服务器发送数据以创建资源。请求体的类型由Content-Type报头表示。它通常会导致服务器的状态变化或副作用

PUT:创建一个新资源或用请求有效负载替换目标资源的表示

PATCH:用于对资源应用部分修改

DELETE:删除指定资源

TRACE:它沿着通往目标资源的路径执行消息循环测试,提供了一种有用的调试机制

OPTIONS:用于描述目标资源的通信选项,客户端可以为OPTIONS方法指定一个URL,或者一个星号(*)来引用整个服务器。

HEAD:它请求与GET请求相同的响应,但没有响应体

CONNECT:它建立到目标资源标识的服务器的隧道,可用于访问使用SSL (HTTPS)的网站

只有语义。

HTTP PUT应该接受请求体,然后将其存储在由URI标识的资源中。

HTTP POST更为通用。它应该在服务器上发起一个操作。该操作可以是将请求体存储在由URI标识的资源中,也可以是不同的URI,也可以是不同的操作。

PUT类似于文件上传。对URI的put操作恰好影响该URI。对URI的POST可以产生任何效果。

其他人已经发布了很好的答案,我只是想补充一点,在大多数语言、框架和用例中,你会更多地使用POST,而不是PUT。PUT、DELETE等基本都是鸡毛蒜毛的问题。

简单来说,你可以说:

1.HTTP Get:用于获取一个或多个条目

2.HTTP Post:用于创建条目

3.HTTP Put:用于更新条目

4.HTTP补丁:用于部分更新项目

5.HTTP删除:用于删除项目