【问题标题】:Are URL.getRef() and URI.getFragment() the same?URL.getRef() 和 URI.getFragment() 是否相同?
【发布时间】:2018-10-17 13:09:07
【问题描述】:

URL.getRef() 和 URI.getFragment() 一样吗?

如果不是,它们有何不同?

运行以下测试时,结果是一样的:

String url = "http://c.b.a.com:1234/path?p1=1&p2=2#somewhere";
System.out.println(new URL(url).getRef());
System.out.println(new URI(url).getFragment());

输出:

somewhere
somewhere

【问题讨论】:

    标签: java url uri


    【解决方案1】:

    是的。他们是一样的东西。 URL 的javadoc 表示:

    一个 URL 可能附加了一个“片段”,也称为“ref”或“reference”。片段由尖号字符“#”表示,后跟更多字符。

    【讨论】:

    • 它们并不完全相同。如果您已转义序列,则 URI 的 getFragment 将对它们进行解码,而 URL 的 getRef 则不会。 URL 的 getRef 与 URI 的 getRawFragment 相同。
    猜你喜欢
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    • 2010-09-17
    • 2013-05-26
    • 1970-01-01
    • 2012-05-08
    相关资源
    最近更新 更多