为什么即使参数不是 URL 编码的,某些查询字符串也能工作? [英] Why do some query strings work even if parameters are not URL-encoded?

查看:22
本文介绍了为什么即使参数不是 URL 编码的,某些查询字符串也能工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个例子:

https://drive.google.com/viewerng/viewer?embedded=true&url=http://journals.plos.org/plosone/s/file?id=wjVg/PLOSOne_formatting_sample_main_body.pdf

url 参数 http://journals.plos.org/plosone/s/file?id=wjVg/PLOSOne_formatting_sample_main_body.pdf 未编码.它包含保留字符,如冒号、斜线和问号.

The url parameter, http://journals.plos.org/plosone/s/file?id=wjVg/PLOSOne_formatting_sample_main_body.pdf, is not encoded. It contains reserved characters, like the colon, slashes, and question mark.

为什么这仍然有效?如果没有它,为什么还要编码?

Why does this still work? And why bother encoding if it works without it?

推荐答案

URI 的保留字符主要用作分隔符——这并不意味着它们不能被使用,这仅意味着它们有特殊用途,如果您不需要它们用于此目的,你必须对它们进行百分比编码.

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-z, A-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.

这篇关于为什么即使参数不是 URL 编码的,某些查询字符串也能工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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