0

I have a URL like this

http://my.my.info/action/doning/something?mailParams=iCgGugAIdMW3CqkYbZ/dGYVqljerVjzbKLvTQCyuosHzxisIrgYf8rcKqRhtn90Z0eVGZ+vx43P4g+umFmddNdDufWv/nDwbCgqBwHs9OYVd5g4VKuFO4jTfF1NiW+KjUi3JubtJT+0F7p+wPHEpTRwJJ+O0eevojx6DioK3cLGejz5UdfIrqzOVNT05TaPKFie4yZxbXfA=

I need it in key value pair not as a query string.

my out put should be

mailParams = iCgGugAIdMW3CqkYbZ/dGYVqljerVjzbKLvTQCyuosHzxisIrgYf8rcKqRhtn90Z0eVGZ+vx43P4g+umFmddNdDufWv/nDwbCgqBwHs9OYVd5g4VKuFO4jTfF1NiW+KjUi3JubtJT+0F7p+wPHEpTRwJJ+O0eevojx6DioK3cLGejz5UdfIrqzOVNT05TaPKFie4yZxbXfA=

i could not parse this string since the above is encoded. I have used URLEncodedUtils to parse this but it returns

mailParams = iCgGugAIdMW3CqkYbZ/dGYVqljerVjzbKLvTQCyuosHzxisIrgYf8rcKqRhtn90Z0eVGZ vx43P4g umFmddNdDufWv/nDwbCgqBwHs9OYVd5g4VKuFO4jTfF1NiW KjUi3JubtJT 0F7p wPHEpTRwJJ O0eevojx6DioK3cLGejz5UdfIrqzOVNT05TaPKFie4yZxbXfA 

which is not at all relevant can some one help me to do this?

4
  • I think plus sign translates to a space Commented Apr 21, 2014 at 6:26
  • I know that the plus is translated i need how to fetch that parameter from that string.. Commented Apr 21, 2014 at 6:27
  • and equal signs must be escaped in an url Commented Apr 21, 2014 at 6:27
  • 2
    Make up your mind. Either you want the + or you want it decoded, correctly, to a space. And if you want the +, why? It wasn't sent that way, and if it was it shouldn't have been: don't compensate for a bug by adding another one. Commented Apr 21, 2014 at 6:47

3 Answers 3

3

Try using java.net.URL

A sample code below.

    URL aURL = new URL("http://my.my.info/action/doning/something?mailParams=iCgGugAIdMW3CqkYbZ/dGYVqljerVjzbKLvTQCyuosHzxisIrgYf8rcKqRhtn90Z0eVGZ+vx43P4g+umFmddNdDufWv/nDwbCgqBwHs9OYVd5g4VKuFO4jTfF1NiW+KjUi3JubtJT+0F7p+wPHEpTRwJJ+O0eevojx6DioK3cLGejz5UdfIrqzOVNT05TaPKFie4yZxbXfA=");

    System.out.println("protocol = " + aURL.getProtocol());
    System.out.println("authority = " + aURL.getAuthority());
    System.out.println("host = " + aURL.getHost());
    System.out.println("port = " + aURL.getPort());
    System.out.println("path = " + aURL.getPath());
    System.out.println("query = " + aURL.getQuery());
    System.out.println("filename = " + aURL.getFile());
    System.out.println("ref = " + aURL.getRef());
Sign up to request clarification or add additional context in comments.

Comments

1

If need to split the link to get the parameters

use String#split which takes the regex as a arguments

String link="http://my.my.info/action/doning/something?mailParams=iCgGugAIdMW3CqkYbZ/dGYVqljerVjzbKLvTQCyuosHzxisIrgYf8rcKqRhtn90Z0eVGZ+vx43P4g+umFmddNdDufWv/nDwbCgqBwHs9OYVd5g4VKuFO4jTfF1NiW+KjUi3JubtJT+0F7p+wPHEpTRwJJ+O0eevojx6DioK3cLGejz5UdfIrqzOVNT05TaPKFie4yZxbXfA=";
        String[] mailparams=link.split("\\?");
        System.out.print(mailparams[1]);

You can also Use URL#getQuery

String link="http://my.my.info/action/doning/something?mailParams=iCgGugAIdMW3CqkYbZ/dGYVqljerVjzbKLvTQCyuosHzxisIrgYf8rcKqRhtn90Z0eVGZ+vx43P4g+umFmddNdDufWv/nDwbCgqBwHs9OYVd5g4VKuFO4jTfF1NiW+KjUi3JubtJT+0F7p+wPHEpTRwJJ+O0eevojx6DioK3cLGejz5UdfIrqzOVNT05TaPKFie4yZxbXfA=";
         URL aURL = new URL(link);
        System.out.println( aURL.getQuery());

OUTPUT:

mailParams=iCgGugAIdMW3CqkYbZ/dGYVqljerVjzbKLvTQCyuosHzxisIrgYf8rcKqRhtn90Z0eVGZ+vx43P4g+umFmddNdDufWv/nDwbCgqBwHs9OYVd5g4VKuFO4jTfF1NiW+KjUi3JubtJT+0F7p+wPHEpTRwJJ+O0eevojx6DioK3cLGejz5UdfIrqzOVNT05TaPKFie4yZxbXfA=

2 Comments

@ashokramcse it will returns your excepted output isn't ?
K what happens when i split your query using =
0
URL aURL = null;
try {
    aURL = new URL("http://my.my.info/action/doning/something?mailParams=iCgGugAIdMW3CqkYbZ/dGYVqljerVjzbKLvTQCyuosHzxisIrgYf8rcKqRhtn90Z0eVGZ+vx43P4g+umFmddNdDufWv/nDwbCgqBwHs9OYVd5g4VKuFO4jTfF1NiW+KjUi3JubtJT+0F7p+wPHEpTRwJJ+O0eevojx6DioK3cLGejz5UdfIrqzOVNT05TaPKFie4yZxbXfA=");
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

System.out.println(aURL.getQuery());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.