我想使用MultipartEntity向PHP服务器发送一张图片和一个JsonObject。以下是我的代码:
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,则没有任何反斜杠,我也就没有问题。
json
对象的? - MKJParekh