My Android Code :
HttpClient client=new DefaultHttpClient();
HttpPost request=null;
for(StudentInfo stdInfo : stdInfoList) {
JSONObject reqObject=dao.createjsonreq(stdInfo);
StringEntity requestSet = new StringEntity(reqObject.toString());
//appUrl = http://192.168.1.1/StudentInfo/std?
request=new HttpPost(appUrl+"Request="+URLEncoder.encode(reqObject.toString()));
//now URl is = http://192.168.1.1/StudentInfo/std?Request={"RequestData":{"StringImge":"/9A/.."}}
requestSet.setContentType("application/json;charset=UTF-8");
requestSet.setContentEncoding(new BasicHeader
(HTTP.CONTENT_TYPE,"application/json;charset=UTF-8"));
request.setEntity(requestSet);
HttpResponse response=client.execute(request);
.....
}
Here in createjsonrequest
creation method
JSONObject sentRequestJson = new JSONObject();
JSONObject sentRequestJson = new JSONObject();
Bitmap image=BitmapFactory.decodeFile(stdInfo.getPicFile());
ByteArrayOutputStream baosimg = new ByteArrayOutputStream();
if (image != null) {
image.compress(Bitmap.CompressFormat.PNG,60,baos);
byte[] byteimg=baosimg.toByteArray();
String strImage = Base64.encodeToString(byteimg, Base64.DEFAULT);
requestJsonObj.put("StringImage",strImage );
}
sentRequestJson.put("RequestData":requestJsonObj);
return sentRequestJson;
My Servlet Code :
log.debug("I got request");
req.setCharacterEncoding("UTF-8");
Enumeration<String> parameterNames = req.getParameterNames();
while (parameterNames.hasMoreElements()) {
String jsonObject = parameterNames.nextElement();
log.debug(jsonObject + "names");
}
When I send POST request from android app to java server it doesn't executes any code in java server (I am given debugs) (when I debug in android I see a base64 image string),
If I use android code requestJsonObj.put("StringImage","");
then request calling to server and debugs executing.
Any help please. Any change in content type for base64 string image.