且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么即使参数未经过URL编码,某些查询字符串仍然有效?

更新时间:2023-02-24 09:34:21

保留的字符通常用作定界符-这并不意味着它们可能不被使用,仅意味着它们具有特殊用途,并且如果您不需要此用途,则必须对它们进行百分比编码.

The reserved characters of an URI are mostly used as delimiters -- it doesn’t mean that they may not be used, it only means that they have a special purpose, and if you don’t need them for this purpose, you have to percent-encode them.

查询组件以第一个?开头,以第一个#结尾(如果有的话,否则以URI的结尾).对于查询组件本身,没有定义保留字符.

The query component starts with the first ? and ends with the first # (if any, otherwise with the end of the URI). For the query component itself, there are no reserved characters defined.

URI标准RFC 3986 定义查询组件可以包含这些字符:

The URI standard RFC 3986 defines that the query component can contain these characters:

  • a-zA-Z
  • 0-9
  • / ? : @ ! $ & ' ( ) * + , ; = . _ ~
  • 百分号字符
  • a-z, A-Z
  • 0-9
  • / ? : @ ! $ & ' ( ) * + , ; = - . _ ~
  • percent-encoded characters

它甚至明确提到:

斜杠("/")和问号(?")可能表示查询组件中的数据.

The characters slash ("/") and question mark ("?") may represent data within the query component.


示例URI的查询组件是这样的:


The query component of your example URI is this:

embedded=true&url=http://journals.plos.org/plosone/s/file?id=wjVg/PLOSOne_formatting_sample_main_body.pdf

除字母外,它还包含=&:/.?_,所有这些在查询中都是允许的.

Apart from letters, it contains =, &, :, /, ., ?, _, all of which are allowed in the query.

请注意,查询组件中的name=value格式(由&分隔)只是一个惯例,而不是规范中定义的内容.

Note that the name=value format (separated by &) in the query component is just a convention, not something defined in the specification.