带请求正文的HTTP GET [英] HTTP GET with request body

查看:128
本文介绍了带请求正文的HTTP GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我们的应用程序开发新的RESTful Web服务.

I'm developing a new RESTful webservice for our application.

在某些实体上执行GET时,客户端可以请求实体的内容. 如果他们想添加一些参数(例如对列表进行排序),则可以在查询字符串中添加这些参数.

When doing a GET on certain entities, clients can request the contents of the entity. If they want to add some parameters (for example sorting a list) they can add these parameters in the query string.

或者,我希望人们能够在请求正文中指定这些参数. HTTP/1.1 似乎并未明确禁止这样做.这样一来,他们可以指定更多信息,也可以更轻松地指定复杂的XML请求.

Alternatively I want people to be able to specify these parameters in the request body. HTTP/1.1 does not seem to explicitly forbid this. This will allow them to specify more information, might make it easier to specify complex XML requests.

我的问题:

  • 这是个好主意吗?
  • HTTP客户端在GET请求中使用请求主体时会遇到问题吗?

http://tools.ietf.org/html/rfc2616

推荐答案

是的.换句话说,任何HTTP请求消息都允许包含消息正文,因此必须在解析消息时牢记这一点.但是,GET的服务器语义受到限制,以使主体(如果有的话)对请求没有语义含义.解析要求与方法语义要求是分开的.

Yes. In other words, any HTTP request message is allowed to contain a message body, and thus must parse messages with that in mind. Server semantics for GET, however, are restricted such that a body, if any, has no semantic meaning to the request. The requirements on parsing are separate from the requirements on method semantics.

所以,是的,您可以使用GET发送正文,否,这样做永远没有用.

So, yes, you can send a body with GET, and no, it is never useful to do so.

这是HTTP/1.1分层设计的一部分,一旦对规范进行了划分(正在开发中),它将再次变得清晰.

This is part of the layered design of HTTP/1.1 that will become clear again once the spec is partitioned (work in progress).

....罗伊

是的,您可以使用GET发送请求正文,但它没有任何意义.如果您通过在服务器上对其进行解析并根据其内容更改响应来赋予其含义,则您将忽略

Yes, you can send a request body with GET but it should not have any meaning. If you give it meaning by parsing it on the server and changing your response based on its contents, then you are ignoring this recommendation in the HTTP/1.1 spec, section 4.3:

...如果请求方法不包含实体主体的已定义语义,则消息主体

...if the request method does not include defined semantics for an entity-body, then the message-body SHOULD be ignored when handling the request.

HTTP/1.1规范的9.3节中有关GET方法的说明:

GET方法意味着检索Request-URI标识的任何信息([...]).

The GET method means retrieve whatever information ([...]) is identified by the Request-URI.

声明请求主体不是GET请求中资源标识的一部分,只是请求URI.

which states that the request-body is not part of the identification of the resource in a GET request, only the request URI.

更新

将RFC2616称为"HTTP/1.1规范".现在已过时.在2014年,它被RFC 7230-7237取代.引用处理请求时应忽略消息正文".已被删除.现在只是请求消息框架独立于方法语义,即使该方法未定义消息主体的任何用法".第二个引号"GET方法意味着检索由Request-URI标识的任何信息...".已被删除. -来自评论

The RFC2616 referenced as "HTTP/1.1 spec" is now obsolete. In 2014 it was replaced by RFCs 7230-7237. Quote "the message-body SHOULD be ignored when handling the request" has been deleted. It's now just "Request message framing is independent of method semantics, even if the method doesn't define any use for a message body" The 2nd quote "The GET method means retrieve whatever information ... is identified by the Request-URI" was deleted. - From a comment

来自 HTTP 1.1 2014规范:

GET请求消息中的有效载荷没有定义的语义;在GET请求上发送有效内容正文可能会导致某些现有实现拒绝该请求.

A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.

这篇关于带请求正文的HTTP GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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