TL;TR:是查询的 URL 部分中的(第一个)问号还是只是一个分隔符,然后是查询?
RFC 1738 ,第 3.3 节,建议使用“?” (问号) 不是查询字符串的一部分,只是将它与路径分开:
http://<host>:<port>/<path>?<searchpart>
RFC 3986 中介绍的语法, 附录 A.,也注明“?”不是实际查询字符串的一部分:
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
现在,让我们考虑两个 URL:
http://server.com/api/item.json
http://server.com/api/item.json?
它们是等效的还是不同的?
区分它们并用于识别两种不同的资源是否有效?
最佳答案
tl;博士:
?
不是查询组件的一部分。 URI 标准 ( STD 66 ) 当前为 RFC 3986 .
栏目 6.2. Comparison Ladder描述了如何测试 URI 是否可能等效的方法。
在 6.2.3. Scheme-Based Normalization它说:
Normalization should not remove delimiters when their associated component is empty unless licensed to do so by the scheme specification. For example, the URI
http://example.com/?
cannot be assumed to be equivalent to any of the examples above.
其中“上述示例”是指:
http://example.com http://example.com/ http://example.com:/ http://example.com:80/
(这 4 个 URI 是等效的。)
所以
http://example.com/api/item.json
没有查询组件,而 http://example.com/api/item.json?
有一个空的查询组件。
关于url - 查询字符串的 URL 部分是问号吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34098717/