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
并未进行编码。它包含保留字符,如冒号、斜杠和问号。URI的保留字符大多用作分隔符--这并不意味着它们不能被使用,只是意味着它们有特殊的目的。如果你不需要用于此目的,那么就必须进行百分号编码。
查询组件以第一个?
开始,并以第一个#
(如果有的话,否则以URI的结尾) 结束。对于查询组件本身,没有定义保留字符。
URI标准RFC 3986 定义查询组件可以包含以下字符:
a
-z
,A
-Z
0
-9
/
?
:
@
!
$
&
'
(
)
*
+
,
;
=
-
.
_
~
甚至明确提到:
斜杠(“/”)和问号(“?”)可能代表查询组件内的数据。
embedded=true&url=http://journals.plos.org/plosone/s/file?id=wjVg/PLOSOne_formatting_sample_main_body.pdf
除了字母外,查询中还包含=
、&
、:
、/
、.
、?
、_
等字符,这些字符都是允许在查询中使用的。
请注意,查询组件中的name=value
格式(由&
分隔)只是一种约定,而不是规范中定义的内容。
因为在 URL 中有些字符具有特殊含义,所以问号(?)用于将路径与查询分开,而和号(&)则用作键值对之间的分隔符。因此,对于像这样的字符,如果我们将它们用作查询字符串中的值,则浏览器会变得混乱。我们使用编码来确保数据不会有歧义。所有这些字符都不会被视为有歧义,因为它们在 HTTP URL 架构中被用于有效的位置。
这是来自相关的RFC 1738:
https://www.ietf.org/rfc/rfc1738.txt
3.3. HTTP
The HTTP URL scheme is used to designate Internet resources
accessible using HTTP (HyperText Transfer Protocol).The HTTP protocol is specified elsewhere. This specification only
describes the syntax of HTTP URLs.An HTTP URL takes the form:
http://<host>:<port>/<path>?<searchpart>
where and are as described in Section 3.1. If : is omitted, the port defaults to 80. No user name or password is
allowed.<path>
is an HTTP selector, and<searchpart>
is a query
string. The<path>
is optional, as is the<searchpart>
and its
preceding "?". If neither<path>
nor<searchpart>
is present, the "/" may also be omitted.Within the
<path>
and<searchpart>
components, "/", ";", "?" are
reserved. The "/" character may be used within HTTP to designate a
hierarchical structure.
"http://" 中的特殊字符仅适用于 URL 开头的 "协议" 规范。在大多数浏览器中,它是可选的(隐含为 "http://")。
第一个 "?" 将 "路径" 与 "搜索部分" 分开。每个 "&" 将 "搜索部分" 中的不同参数分开。
您的浏览器应该区分 ?embedded=true
和 &url=http://www.pdf995.com/samples/pdf.pdf
。
希望这有所帮助。
=
和&
),如果这些字符出现在数据的一部分中,它们必须进行百分号编码(以使站点工作,而不是根据规范)。 - unor