3

I'm using the following code to encode a url and then decode it and use it in my project but i keep getting errors and the app crashes when i try to load a url on this code

any guidance is appreciated

private static String getURL() {
    String base64URL = "http://www.domain.dom/folder/folder2/2.json";
    byte[] data = Base64.decode(base64URL, Base64.NO_CLOSE);
    String text = new String(data, StandardCharsets.UTF_8);
    return text;}

Error:

java.lang.IllegalArgumentException: bad base-64
4
  • "http://www.domain.dom/folder/folder2/2.json" is not a valid Base64 string ... Perhaps you want to download the data from that URL first? Commented Jan 7, 2017 at 22:21
  • Why is that not a valid base64 string? Commented Jan 7, 2017 at 22:24
  • Because it isn't in base64 at all. Read en.wikipedia.org/wiki/Base64 Commented Jan 7, 2017 at 23:02
  • Also- encoding a URL in base 64 would be really really weird. There's pretty much no reason to ever do that. The purpose of Base64 is to encode binary data into a text string as a hack to send it somewhere that sends text. A URL is already text, so using it would be pointless. Commented Jan 7, 2017 at 23:04

1 Answer 1

2

Try this, Base64.NO_WRAP or Base64.NO_PADDING this both are working for me.

I hope it helps you.

Sign up to request clarification or add additional context in comments.

1 Comment

Tried but crash again

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.