MultipartEntity を使用して、画像と JsonObject を PHP サーバーに送信したいと考えています。ここに私のコードがあります:
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);
形式が次のようなものであるため、php でこれを読み取ることができません。
{\"test1\":\"Z\",\"test2\":\"1\"}
バックスラッシュが原因で、php でこれを読み取ることができません。httppost と bytearrayentity に画像なしで json を投稿すると、バックスラッシュはなく、問題はありません。