2

I am trying to get the values from a webpage, and to get the values i have put %20 between the different values. But chrome is replacing %20 to %2520 because of which i am not getting correct values.

ex: i am trying to read values of url :

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

and %20 automatically got replaced by %2520 when i press enter.

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

I have searched this issue in lots of posts but didn't find my solution.

and when i try reading something with url below:

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

then also it is converting " "(space) to %2520 see below:

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

Kindly help.

Sangeeta
  • 961
  • 2
  • 13
  • 34
  • My Suggestion, use a different delimiter like a `-`. Or avoid double encoding URI. – Uma Kanth Dec 30 '15 at 07:30
  • This isn't a Java or Android question. It's not really an http or get question, either -- this is really a Chrome question. That said, I can't repro this, using http://httpbin.org/get?q=a%20b. That page shows the arg `q` with a value of `a b`, which is what I'd expect -- and is different from what it would be if Chrome replaced the `%` with `%25`. – yshavit Dec 30 '15 at 07:30
  • but it used to run fine earlier.. i dnt know why its not running today @uma – Sangeeta Dec 30 '15 at 07:41
  • i have seen that post also but didnt help @Uma – Sangeeta Dec 30 '15 at 07:41
  • what should i do now @yshavit – Sangeeta Dec 30 '15 at 07:42
  • @Sangeeta I don't know, it's hard to debug with that little info. Are you absolutely sure it's Chrome that's doing the substitution, and not something else (maybe you're encoding a string that's already been encoded)? This seems like something that's happening on the server side of things, not in Chrome. – yshavit Dec 30 '15 at 08:04
  • you can say that, i am making a url using my android application and when i paste it into chrome i get this issue. – Sangeeta Dec 30 '15 at 08:05

2 Answers2

2

Unfortunately %25 is the code for the % character and so somehow your %20 is not getting encoded properly. You could try find and replacing the %20 with actual spaces. I know that fix has worked on other occasions. Otherwise, consider a link shortener as a work around.

James Abela
  • 97
  • 1
  • 3
0

You don't want to include the %20 in the URL, otherwise it will indeed be replaced with %2520.

What worked for me is to create a URI and set it to contain the desired URL, and then create a URL from the URI. When you do this, do not use %20, use literal spaces. After that, create a URL from the URI, and output the URL using the toExternalForm method.

For example:

    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();
    }

This worked for me on Android and Java platforms.

Zeth
  • 86
  • 3