重复 HTTP GET 查询键的权威位置 [英] Authoritative position of duplicate HTTP GET query keys

查看:22
本文介绍了重复 HTTP GET 查询键的权威位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到有关 HTTP GET 查询字符串重复字段行为的权威信息,例如

I am having trouble on finding authoritative information about the behavior with HTTP GET query string duplicate fields, like

http://example.com/page?field=foo&field=bar 

尤其是订单是否保留.大多数面向 Web 的语言都会生成一个包含与键字段"相关联的 foo 和 bar 的数组,但我想知道是否存在关于这一点的权威声明(例如在 RFC 上).RFC 3986 有一个部分 3.4.查询,指的是key=value 对,但是没有说明如何解释顺序和重复字段等.这是有道理的,因为它依赖于后端,而不在该 RFC 的范围内...

and in particular if the order is kept or not. Most web-oriented languages produce an array containing both foo and bar associated to a key "field", but I would like to know if authoritative statement exist (e.g. on a RFC) about this point. RFC 3986 has a section 3.4. Query, which refers to key=value pairs, but nothing is said on how to interpret order and duplicate fields and so on. This makes sense, since it's backend dependent, and not in the scope of that RFC...

尽管存在事实上的标准,但出于好奇,我还是想看看它的权威来源.

Although a de-facto standard exists, I'd like to see an authoritative source for it, just out of curiosity.

推荐答案

没有规范.你可以做你喜欢做的事.

There is no spec on this. You may do what you like.

典型的方法包括:首先给定、最后给定、全部数组、字符串连接和逗号全部.

Typical approaches include: first-given, last-given, array-of-all, string-join-with-comma-of-all.

假设原始请求是:

GET /blog/posts?tag=ruby&tag=rails HTTP/1.1
Host: example.com

对于request.query['tag'] 应该产生什么,有各种选项,具体取决于语言或框架:

Then there are various options for what request.query['tag'] should yield, depending on the language or the framework:

request.query['tag'] => 'ruby'
request.query['tag'] => 'rails'
request.query['tag'] => ['ruby', 'rails']
request.query['tag'] => 'ruby,rails'

这篇关于重复 HTTP GET 查询键的权威位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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