gpt4 book ai didi

http - 路径部分中带有//的 URL 是否有效?

转载 作者:可可西里 更新时间:2023-11-01 15:04:16 25 4
gpt4 key购买 nike

我有一个关于 URL 的问题:

我读过 RFC 3986并且仍然对一个 URL 有疑问:

If a URI contains an authority component, then the path component
must either be empty or begin with a slash ("/") character. If a URI does not contain an authority component, then the path cannot begin
with two slash characters ("//"). In addition, a URI reference
(Section 4.1) may be a relative-path reference, in which case the
first path segment cannot contain a colon (":") character. The ABNF
requires five separate rules to disambiguate these cases, only one of which will match the path substring within a given URI reference. We use the generic term "path component" to describe the URI substring
matched by the parser to one of these rules.

我知道,//server.com:80/path/info 是有效的(它是模式相对 URL)

我也知道 http://server.com:80/path//info 是有效的。

但我不确定下面的是否有效:

http://server.com:80//path/info

我的问题背后的问题是,当由 URI http:/创建时,cookie 不会发送到 http://server.com:80//path/info/server.com:80/path/info 限制为 /path

最佳答案

参见 url with multiple forward slashes, does it break anything? , Are there any downsides to using double-slashes in URLs? , What does the double slash mean in URLs?RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax .

共识:浏览器将按原样处理请求,不会更改请求。 / 字符是路径分隔符,但作为路径段定义为:

path-abempty  = *( "/" segment )
segment = *pchar

表示 http://example.com/ 之后的斜杠可以直接跟另一个斜杠,无限次。服务器可能会忽略它,但浏览器不会,如您所知。

短语:

If a URI does not contain an authority component, then the path cannot beginwith two slash characters ("//").

允许protocol-relative URLs ,但在这种情况下明确说明可能不存在权限(server.com:80 在您的示例中)。

所以:是的,它是有效的,不,不要使用它。

关于http - 路径部分中带有//的 URL 是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20523318/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com