I want to send an image and JsonObject to a PHP server with MultipartEntity. Here is my code:
HttpClient httpClient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(urlString); File file = new File(imageend); HttpResponse response = null; MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file, "image/jpeg"); StringBody sb; try { sb = new StringBody(json.toString()); mpEntity.addPart("foto", cbFile); mpEntity.addPart("json", sb); httppost.setEntity(mpEntity); response = httpClient.execute(httppost);
I cannot read this in php because the format is similar:
{\"test1\":\"Z\",\"test2\":\"1\"}
I cannot read this in php due to backslashes. If I send json without image via httppost and bytearrayentity, there are no backslashes, and I have no problem.
source share