Hello i am using loopJ Asynchronous Http Client for posting values to a webservice. The problem i am facing is. I encode my Bitmap to Base64 String and use this string as a parameter for the webservice. I always get the ClientProtocolException and no response. I know there is a problem with the string. But i dont know what the problem is maybe a large string ? I need help.
Here is my code
client.get(
"http://website.com/users.php?task=addGeneralSettings&userID="
+ user.getUserID() + "&vat="
+ URLEncoder.encode(String.valueOf(user.getVat()))
+ "&company=" + URLEncoder.encode(user.getCompany())
+ "&address1=" + URLEncoder.encode(user.getAddress1())
+ "&address2=" + URLEncoder.encode(user.getAddress2())
+ "&telephone=" + user.getTelephone() + "&fax="
+ user.getFax() + "&email=" + user.getEmail()
+ "&website=" + URLEncoder.encode(user.getWebsite())
+ "&vatNum=" + URLEncoder.encode(user.getVatno())
+ "&CompanyReg="
+ URLEncoder.encode(user.getCompanyNum()) + "&logo="
+ (user.getLogo()), new AsyncHttpResponseHandler() {
public void onSuccess(String response) {
Log.v("web response ", response);
try {
json = new JSONObject(response);
if (json.getBoolean("status")) {
delegate.settingsAdded(user.getLogo());
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
The getLogo() is my base64 String. Which is huge in length. I am using the following code to convert the Image to Base64 string.
public static String encodeTobase64(Bitmap image) {
Bitmap immagex = image;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
immagex.compress(Bitmap.CompressFormat.JPEG, 80, baos);
byte[] b = baos.toByteArray();
String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
return imageEncoded;
}