I have a simple program which tries to decode an encoded URL. But for some reason this doesn't seem to be wo开发者_JS百科rking. 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.
The string you are sending is not URL encoded, so it can't be decoded. Where did you get the string?
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
It's doing exactly what it's supposed to. There is nothing to change.
精彩评论