PUT和POST请求是否需要/预期有请求正文? [英] Are PUT and POST requests required/expected to have a request body?

查看:165
本文介绍了PUT和POST请求是否需要/预期有请求正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个RESTful api,而我正在考虑用户创建密钥的过程。我有以下可能性:

I'm writting a RESTful api, and at I'm thinking about the process of a user creating a key. I have the following possibilities:


  • 获取 / new /< keyname> - 虽然这很容易,但我认为我不会使用它,因为我听说GET用于检索和/或列出信息;

  • POST请求到 /< ; keyname> - 这在我看来简单易行,但不会在请求正文中传递任何数据。我可以这样做吗?这有点奇怪吗?

  • POST请求到 / keys 传递请求正文keyname = SomeKey - 这是正确的方法吗?

  • GET request to /new/<keyname> - although it's very easy I think I won't use this, because I heard GET is for retrieving and/or listing information;
  • POST request to /<keyname> - This seemed to me easy and simple enough, but does not pass any data in the request body. Can I do it this way ? Is this weird ?
  • POST request to /keys passing in the request body "keyname=SomeKey" - Is this the correct way ?

我看了来自joyent的这个API 以及他们在所有PUT和POST请求中他们在请求正文中传递一些数据。这是预期的吗?在PUT和POST请求中不要求请求正文是否真的错了?

I looked at this API from joyent and in all their PUT and POST requests they pass some data in the request body. Is this expected ? Is it really wrong not to require a request body in a PUT and POST request ?

推荐答案

我在Http-上问过这个问题WG。这是我得到的最准确的答案 http://lists.w3.org/档案/公共/ ietf-http-wg / 2010JulSep / 0276.html

I asked this question on the Http-WG. This was the most precise answer I got http://lists.w3.org/Archives/Public/ietf-http-wg/2010JulSep/0276.html

总之,POST不需要正文。我希望可以将相同的理由应用于PUT。

In summary, POST does not require a body. I would expect the same justification can be applied to PUT.

这篇关于PUT和POST请求是否需要/预期有请求正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆