带请求正文的HTTP

带请求正文的HTTP

本文介绍了带请求正文的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

推荐答案

罗伊·菲尔丁(Roy Fielding)的评论,其中包括带有GET请求的车身.

所以,是的,您可以使用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发送请求正文,但它没有任何意义.如果您通过在服务器上对其进行解析并根据其内容更改响应来赋予其含义,则您将忽略 HTTP/1.1规范,第4.3节:

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:

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

声明请求主体不是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规范:

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

07-30 22:21