Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

When doing a GET on certain entities, clients can request the contents of the entity.

(在某些实体上执行GET时,客户端可以请求实体的内容。)

If they want to add some parameters (for example sorting a list) they can add these parameters in the query string.

(如果他们想添加一些参数(例如,对列表进行排序),则可以在查询字符串中添加这些参数。)

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.

(HTTP / 1.1似乎没有明确禁止这样做。)

This will allow them to specify more information, might make it easier to specify complex XML requests.

(这将使他们能够指定更多信息,可能使指定复杂的XML请求更加容易。)

My questions:

(我的问题:)

  • Is this a good idea altogether?

    (这是个好主意吗?)

  • Will HTTP clients have issues with using request bodies within a GET request?

    (HTTP客户端在GET请求中使用请求主体时会遇到问题吗?)

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

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

  ask by Evert translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
330 views
Welcome To Ask or Share your Answers For Others

1 Answer

Roy Fielding's comment about including a body with a GET request .

(罗伊·菲尔丁(Roy Fielding)的评论,其中包括一个带有GET request的物体 。)

Yes.

(是。)

In other words, any HTTP request message is allowed to contain a message body, and thus must parse messages with that in mind.

(换句话说,任何HTTP请求消息都允许包含消息主体,因此必须在解析消息时牢记这一点。)

Server semantics for GET, however, are restricted such that a body, if any, has no semantic meaning to the request.

(但是,GET的服务器语义受到限制,以使主体(如果有的话)对请求没有语义含义。)

The requirements on parsing are separate from the requirements on method semantics.

(解析要求与方法语义要求分开。)

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

(因此,是的,您可以使用GET发送正文,否,这样做永远没有用。)

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

(这是HTTP / 1.1分层设计的一部分,一旦对规范进行了分区(工作正在进行中),它??将再次变得清晰。)

....Roy

(....罗伊)

Yes, you can send a request body with GET but it should not have any meaning.

(是的,您可以使用GET发送请求正文,但它没有任何意义。)

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规范第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.

([...]如果请求方法不包括用于一个实体主体定义的语义,则该消息体应该被处理请求时忽略。)

And the description of the GET method in the HTTP/1.1 spec, section 9.3 :

(以及HTTP / 1.1规范第9.3节中 GET方法的描述:)

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

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

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

(声明请求主体不是GET请求中资源标识的一部分,仅是请求URI。)

Update The RFC2616 referenced as "HTTP/1.1 spec" is now obsolete.

(更新现在称为“ HTTP / 1.1规范”的RFC2616已过时。)

In 2014 it was replaced by RFCs 7230-7237.

(在2014年,它被RFC 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.

(现在只是“请求消息框架独立于方法语义,即使该方法未定义消息主体的任何用法”,第二个引号“ GET方法意味着检索任何由请求URI标识的信息……”已被删除。)

- From a comment

(-来自评论)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...