HTTP1.1 Notes 6, Method Definitions

本文详细介绍了HTTP协议中的各种方法,包括GET、POST、PUT、DELETE等,并解释了它们的特点及应用场景。此外,还讨论了诸如TRACE和CONNECT这类较少见的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[b]Safe and Idempotent Methods[/b]

In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval
These methods ought to be considered "safe"
This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested

Methods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request
The methods GET, HEAD, PUT and DELETE share this property
Also, the methods OPTIONS and TRACE SHOULD NOT have side effects, and so are inherently idempotent
A sequence that never has side effects is idempotent

[b]OPTIONS[/b]
The OPTIONS method represents a request for information about the communication options available on the request/response chain identified by the Request-URI
This method allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval
Responses to this method are not cacheable

[b]GET[/b]
The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI
The semantics of the GET method change to a "conditional GET" if the request message includes an If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field
The semantics of the GET method change to a "partial GET" if the request message includes a Range header field

[b]HEAD[/b]
The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response

[b]POST[/b]
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
If a resource has been created on the origin server, the response SHOULD be 201 (Created) and contain an entity which describes the status of the request and refers to the new resource, and a Location header

[b]PUT[/b]
The PUT method requests that the enclosed entity be stored under the supplied 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
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
The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI
A single resource MAY be identified by many different URIs

[b]DELETE[/b]
The DELETE method requests that the origin server delete the resource identified by the Request-URI

[b]TRACE[/b]
The TRACE method is used to invoke a remote, application-layer loop- back of the request message
The final recipient of the request SHOULD reflect the message received back to the client as the entity-body of a 200 (OK) response
A TRACE request MUST NOT include an entity
TRACE allows the client to see what is being received at the other end of the request chain and use that data for testing or diagnostic information

[b]CONNECT[/b]
This specification reserves the method name CONNECT for use with a proxy that can dynamically switch to being a tunnel

一般而言Web Server只支持GET和POST,有的可以通过修改默认配置来支持PUT和DELETE,而有的没有实现TRACE
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值