【问题标题】:Is there a way to know what is the url before it will be encoded?有没有办法在编码之前知道 url 是什么?
【发布时间】:2019-10-25 09:15:58
【问题描述】:

我想知道是否有办法在编码之前知道输入的 URL。

我的问题是,一旦我输入 URL,空格会自动编码为 %20。例如,我有一个具有此参数的 URL ?a=on e

我需要得到这个字符串“a=on e”,因为我需要区分用户输入是空格还是 %20。

【问题讨论】:

  • 添加代码的 sn-p 将大大有助于帮助者帮助您。请这样做。

标签: web url special-characters urlencode space


【解决方案1】:

on%20e 是您从uri 编码获得的数据。所以如果你想从url得到正确的数据,你必须解码查询参数。

例如:

String encodeResult = URLEncoder.encode(q, "UTF-8");    System.out.println(encodeResult); // result is on%20e
String decodeResult =    URLDecoder.decode(encodeResult); System.out.println(decodeResult); // result is on e

您只需要记住只编码单个查询字符串参数名称和/或值,而不是整个URL

【讨论】:

    猜你喜欢
    • 2011-12-10
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多