url - 查询字符串的 URL 部分是问号吗?

标签 url query-string rfc3986 rfc1738

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;博士:

  • ?不是查询组件的一部分。
  • URIs 是不等价的,因为有 无查询组件 ,而另一个有 空查询组件 .


  • 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/

    相关文章:

    javascript - 提交按钮不会将第二个查询字符串添加到 url

    带有查询字符串的 c# webapi

    javascript - 选择选项 onclick 更改 url 或更改 div

    java - URL 证书问题

    javascript - 添加基于子页面 URL 的事件导航类

    swift - 什么样的 URL 不符合 RFC 3986 但符合 RFC 1808、RFC 1738 和 RFC 2732?

    java - 在 Java Servlet 中处理 URL

    C# ASP.NET HttpWebRequest 自动解码查询字符串中的符号 (&) 值?

    java - '+' (plus sign) not encoded with RestTemplate using String url, but interpreted as ''(空格)