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.

4
  • make sure you are passing correct URL, 404 comes when you have done mistake in your URL or web server is not working properly. Commented Jan 25, 2012 at 8: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. Commented Jan 25, 2012 at 10:27
  • try new String(decoded, StandardCharsets.UTF_8); or new String(decoded, Charset.forName("UTF-8") ); Commented Jun 30, 2016 at 8:36
  • Base64.encodeBase64 it requires java 7 then it will be properly encoded to base64. and for Java 8 you can use BaseEncoder stackoverflow.com/a/28305759/3496570 Commented Jun 30, 2016 at 9:00

1 Answer 1

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

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.