Chrome:html空间正在将%20替换为%2520

时间:2015-12-30 07:22:21

标签: java android http get

我正在尝试从网页获取值,并获取我将%20放在不同值之间的值。但是chrome正在将%20替换为%2520,因为我没有得到正确的值。

例如:我正在尝试读取网址的值:

https://..../place?action=list&&device=359299059228937&q=1110%201113%201175%201114%201115%201116%201111%201117%201123%201452%201112%201121%201120%201119%201122

当我按下回车键时,

和%20自动被%2520取代。

https://..../place?action=list&&device=359299059228937&q=1110%25201113%25201175%25201114%25201115%25201116%25201111%25201117%25201123%25201452%25201112%25201121%25201120%25201119%25201122

我在很多帖子中搜索过这个问题,但没有找到我的解决方案。

当我尝试用下面的网址阅读时:

https://..../place?action=list&&device=359299059228937&q=1110 1113 1175 1114 1115 1116 1111 1117 1123 1452 1112 1121 1120 1119 1122

然后它也在转换" "(空格)到%2520见下文:

https://..../place?action=list&&device=359299059228937&q=1110%25201113%25201175%25201114%25201115%25201116%25201111%25201117%25201123%25201452%25201112%25201121%25201120%25201119%25201122

请帮助。

2 个答案:

答案 0 :(得分:1)

不幸的是%25是%字符的代码,所以你的%20不能正确编码。您可以尝试使用实际空格查找并替换%20。我知道修复在其他场合有效。否则,请考虑使用链接缩短程序作为解决方法。

答案 1 :(得分:0)

您不希望在网址中包含%20,否则它确实会被%2520替换。

对我有用的是创建一个URI并将其设置为包含所需的URL,然后从URI创建一个URL。执行此操作时,请不要使用%20,使用文字空格。之后,从URI创建一个URL,并使用toExternalForm方法输出URL。

例如:

    URI uri = null;

    try {
        uri = new URI(
                "http",
                "search.barnesandnoble.com",
                "/booksearch/first book.pdf",
                null);
        URL url = uri.toURL();
        // The content TextView is what I used to test the output
        content.setText(url.toExternalForm());
    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

这适用于Android和Java平台。