0

The string that I want to send contains # because of this, in the server only the string upto # is recieved. How should I use BASE64Encoder in the client side to encode the String. PLease remember that I have a string which contains the #. And how to decode it in the server?

Ashwin
  • 12,691
  • 31
  • 118
  • 190
  • 1
    [BASE64 encoded charset](http://www.garykessler.net/library/base64.html) doesn't have the number sign (#) character. So, you can convert any string with # characters into BASE64 encoded version where the latter doesn't include any #. For example plain-text string `#123` will be `IzEyMw==` in BASE64 encoded form. Perform this on the client side. On the server side, it should decode the BASE64 encoded string back into its plain-text string version. – ecle Apr 14 '12 at 04:17
  • Base64 encodes an arbitrary sequence of bytes. Whatever your problem is, it's not in encoding the `#` character. – Matt Ball Apr 14 '12 at 04:37

2 Answers2

2

Use URLEncoder and URLDecoder classes for this purpose.

String urlParam = URLEncoder.encode(param);

....

String param = URLDecoder.decode(urlParam);
Eugene Retunsky
  • 13,009
  • 4
  • 52
  • 55
  • thanks, it works now. But what was the problem originally? And what does URLEncoder do? – Ashwin Apr 14 '12 at 04:42
  • Sorry for de-accepting your answer. See my question. I have edited it with the problem. – Ashwin Apr 14 '12 at 05:07
  • :I am Sorry your code works now suddenly. I don't know what the problem was but then the difference was visible. Now suddenly it is working fine! – Ashwin Apr 14 '12 at 08:58
1

It looks like you are passing non-url-encoded arguments in query string. You don't need Base64 for it, just url-encode.

See HTTP URL Address Encoding in Java:

URI uri = new URI( 
        "http",  
        "www.google.com",  
        "/ig/api", 
        "weather=São Paulo#123", 
        null); 
String request = uri.toASCIIString(); 
Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179