0

I have a simple program which tries to decode an encoded URL. But for some reason this doesn't seem to be working. Would anybody have any idea why this is happening? I have spent hours but haven't been able to figure it out.

Here is the program:

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class DecodeTest {

public static void main(String[] args) {

    String encodedUrl = "aHR0cHM6Ly93d3cuYWUuY29tL3dlYi9teWFjY291bnQvYWNjb3VudF9ob21lLmpzcA";
    String decodedUrl = "";

    try {
        decodedUrl = URLDecoder.decode(encodedUrl, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    System.out.println("String: " + decodedUrl);
    }
}

The output is as follows:

 String: aHR0cHM6Ly93d3cuYWUuY29tL3dlYi9teWFjY291bnQvYWNjb3VudF9ob21lLmpzcA

This is the same encoded string.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Abhijit
  • 4,853
  • 3
  • 30
  • 33

3 Answers3

4

The string you are sending is not URL encoded, so it can't be decoded. Where did you get the string?

Alex Gitelman
  • 24,429
  • 7
  • 52
  • 49
3

are you sure you don't need a base64 decoder? this is the expect result. URL encoding/decoding is something like transforming spaces in %20 and stuff like that

%0D%0AGood+luck%28you%27ll+need+it%29 

into

Good luck (you'll need it)

base64 decoding will give you

https://www.ae.com/web/myaccount/account_home.jsp

for your input

Pablo Grisafi
  • 5,039
  • 1
  • 19
  • 29
  • Thanks for the response! You are right - I would need to use base64 decoding. How would I go about doing it in java? – Abhijit Oct 11 '11 at 22:50
0

It's doing exactly what it's supposed to. There is nothing to change.

CamelSlack
  • 573
  • 2
  • 7