我想发送一个图像和一个带有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,没有任何反斜杠,我也没有问题。
发布于 2012-11-20 16:27:14
使用以下PHP:
string stripslashes ( string $str )发布于 2012-11-20 16:27:29
也许您可以在PHP端使用preg_replace将\"替换为\
https://stackoverflow.com/questions/13469031
复制相似问题