Joã*_*imo 24 rest post http put httpwebrequest
我正在写一个RESTful api,而我正在考虑用户创建密钥的过程.我有以下几种可能性:
/new/<keyname> - 虽然这很容易,但我认为我不会使用它,因为我听说GET用于检索和/或列出信息;/<keyname> - 这在我看来简单易行,但不会在请求正文中传递任何数据.我可以这样做吗?这有点奇怪吗?/keys传递请求正文"keyname=SomeKey" - 这是正确的方法吗?我从joyent查看了这个API,在他们所有的PUT和POST请求中,他们在请求体中传递了一些数据.这是预期的吗?在PUT和POST请求中不要求请求正文是否真的错了?
Dar*_*ler 15
我在Http-WG问了这个问题.这是我得到的最精确的答案http://lists.w3.org/Archives/Public/ietf-http-wg/2010JulSep/0276.html
总之,POST不需要正文.我希望同样的理由可以应用于PUT.
在最常见的形式中,HTTP消息是这样的(注意可选主体):
generic-message = start-line
*(message-header CRLF)
CRLF
[ message-body ]
start-line = Request-Line | Status-Line
阅读进一步说明:
9.5 POST 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. ...
和
9.6 PUT The PUT method requests that the enclosed entity be stored under the supplied Request-URI. ... 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.
POST和PUT都包含请求中包含的短语实体.
根据我的阅读,我相信POST和PUT都需要一个正文(我知道非规范的描述).
在REST的上下文中,POST是创建的,PUT是更新的.我可以想象创建一个空对象(可能是未来信息的占位符),但我没想到会有太多的空更新.
| 归档时间: |
|
| 查看次数: |
23848 次 |
| 最近记录: |