有嵌套的urlencoded参数[]规范吗? [英] Is there a spec for nested urlencoded params[]?

查看:72
本文介绍了有嵌套的urlencoded参数[]规范吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在历史的某一时刻,服务器端语言开始调整urlencoded参数,以增加对将数据提交为数组和键/值对象的支持:

At one point in history, server side languages started tweaking urlencoded parameters to add support for submitting data as arrays and key/value objects:

// key/value pairs
contact[name]=John
contact[phone]=800-555-1234

// arrays
foo[]=bar
foo[]=baz

我正在一个库的嵌套参数解析中处理一些极端情况,例如保留参数顺序.是否有规范化服务器应如何处理此编码的规范?如果没有,哪个参考实现引入了这种语法?

I’m playing around with some edge cases in one library's nested parameter parsing, eg preservation of parameter order. Is there a spec that formalizes how a server should process this encoding? If not, which reference implementation introduced this syntax?

推荐答案

URI中的方括号

根据 RFC-3986统一资源标识符(URI):通用语法"不允许在URI中使用未编码的方括号.因此,这不是HTTP标准.

According to RFC-3986 "Uniform Resource Identifier (URI): Generic Syntax" using unencoded square brackets in URIs isn't allowed. Therefore it's not a HTTP standard.

由Internet协议文字地址版本6 [RFC3513]或更高版本标识的主机通过将IP文字括在方括号("["和]")中来区分.这是URI语法中唯一允许使用方括号字符的地方.

A host identified by an Internet Protocol literal address, version 6 [RFC3513] or later, is distinguished by enclosing the IP literal within square brackets ("[" and "]"). This is the only place where square bracket characters are allowed in the URI syntax.

许多编程语言都在数组中使用方括号,因此我想在URI中使用方括号是很自然的做法.

Many programming languages are using square brackets for arrays, therefore I guess it was a natural carry-over to use square brackets in URIs.

是否存在规范化服务器应如何处理此编码的规范?

Is there a spec that formalizes how a server should process this encoding?

不,至少不独立于语言.

No, at least not language independent.

首次实施

许多Web应用程序框架都允许重用查询中的相同键来创建数组,例如 http://example.org/?foobar=hello&foobar=world .这些框架还允许在键中使用方括号,但这没什么区别,它们只是名称的一部分.很少支持关联数组.(注意:我对所有这些语言都不熟悉.)

A lot of web application frameworks allow reuse of the same key in the query to create an array, for example http://example.org/?foobar=hello&foobar=world. These frameworks also allow to use square brackets in keys, but it makes no difference, they are just part of the name. Associative arrays are rarely supported. (Caveat: I'm not familiar with all this languages.)

  • Perl,1987年:支持数字数组,但不支持关联数组.
  • PHP,1995:支持带编号的数组以及关联数组.
  • Active Server Pages(ASP),1996:支持带编号的数组,但不支持关联数组.
  • JavaServerPages(JSP),1999:支持带编号的数组,但不支持关联数组.
  • JAX-RS(Java),2008:支持编号数组,但不支持关联数组.

到目前为止,PHP是我发现的唯一语言,它支持URL中的关联数组,而无需自定义代码.

So far PHP is the only language I've found, which supports associative arrays in URLs without custom code.

这篇关于有嵌套的urlencoded参数[]规范吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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