1

I have a little problem and cant solve it myself. Check this little piece of code:

private void setCommand(String cmd, String uid) {
    String b64cmd = new String(Base64.encode(cmd.getBytes(), Base64.DEFAULT));

    try {
        StringBuilder bulitString = new StringBuilder("http://adwi.net84.net/zserver.php?r=setcmd&pwd=123&uid=");
        bulitString.append(uid);
        bulitString.append("&cmd=");
        bulitString.append(b64cmd);


        URL url = new URL(bulitString.toString());
        System.out.println(bulitString.toString());
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.getInputStream();

It just creates and sends request to the server. Everything works fine if the cmd is short enaugh. Debugger prints (this is android app btw) enter image description here

And everything works fine, as excepted. But if I pass something longer to this function I get exception java EOFexception

it looks like that. I dont know, it looks like this string breaks into two strings? What should I do to fix this? Thanks for spending your time.. enter image description here

5
  • 1
    Hmm, maybe a limit in system.out.printLn. Try using Log.d. This is the preferred way to print to debug in android. Commented Apr 12, 2014 at 21:15
  • @weston but it doesn't matter, even if I comment out System.out.println it still throws this exception. Commented Apr 12, 2014 at 21:18
  • OK, well the exception comes from what happens next anyway. So what is after the system.out line? Commented Apr 12, 2014 at 21:20
  • @weston Oh, sorry I added missing lines. Commented Apr 12, 2014 at 21:23
  • I have no idea why it works for shorter strings, and doesnt for longer. Commented Apr 12, 2014 at 21:25

1 Answer 1

1

My theory is your base 64 encoding is inserting new lines. The server only receives one line and gets upset because it represents a fragment of base64 data.

So to disable this use NO_WRAP rather than DEFAULT.

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

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.