8

I am new in android . i have send image to server using Json format as a string.

so i have Encoded image string i.e base64 string.

 Json j =  new JSonObject();

String Image_string = Base64.ToEncodedString(bytearray, Base64.Default);

j.put("image_file_content",Image_string);

But i am getting this error. Please help me..wts wrong

400 Bad Request

Bad Request

Your browser sent a request that this server could not understand.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Pravin Mohol
  • 665
  • 6
  • 17
  • make sure you are passing correct URL, 404 comes when you have done mistake in your URL or web server is not working properly. – Lucifer Jan 25 '12 at 08:49
  • Do you a definition of this API to append to your post? It sounds.. odd and wasteful.. to use JSON to post large binary content to a web server. – Jens Jan 25 '12 at 10:27
  • try new String(decoded, StandardCharsets.UTF_8); or new String(decoded, Charset.forName("UTF-8") ); – Zar E Ahmer Jun 30 '16 at 08:36
  • Base64.encodeBase64 it requires java 7 then it will be properly encoded to base64. and for Java 8 you can use BaseEncoder http://stackoverflow.com/a/28305759/3496570 – Zar E Ahmer Jun 30 '16 at 09:00

1 Answers1

2

Consider using URLEncoder

URLEncoder.encode("String to encode", "UTF-8");

Check out the docs here: http://developer.android.com/reference/java/net/URLEncoder.html

iko_wp
  • 739
  • 6
  • 9