我想在分段图像上传中传递arrayList值"标签"和"类别">
HttpClient httpClient = new DefaultHttpClient();
QuestionPicArray = params[0];
HttpPost httpPost = new HttpPost(UrlLinks.base_url + "/api/forum/create");
httpPost.addHeader(Constants.AUTHORIZATION, sp.getToken(context));
httpPost.addHeader(Constants.contentType, "image/jpeg");
org.apache.http.entity.mime.MultipartEntity entity = new org.apache.http.entity.mime.MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
for (int i = 0; i < QuestionPicArray.size(); i++) {
File sourceFile = new File(QuestionPicArray.get(i).toString());
entity.addPart("file[" + i + "]", new FileBody(sourceFile));
entity.addPart("title", new StringBody( title.toString()));
entity.addPart("desc", new StringBody( desc.toString()));
entity.addPart("askedTo",new StringBody( askedTo.toString()));
if (!askedTo.equalsIgnoreCase("open"))
entity.addPart("anaonFlag",new StringBody(anaonFlag.toString()));
for(int j=0;j<tags.size();j++)
{
// Array
entity.addPart("tags",new StringBody(String.valueOf(tags.get(j)), Charset.forName("EUC-KR")));
}
for(int j=0;j<category.size();j++)
{
// Array
entity.addPart("category",new StringBody(String.valueOf(category.get(j)), Charset.forName("EUC-KR")));
}
}
httpPost.setEntity(entity);
// Making server call
HttpResponse response = httpClient.execute(httpPost);
HttpEntity r_entity = response.getEntity();
getData = EntityUtils.toString(r_entity);
结果是"结果错误:未找到">
请建议我如何在多部分实体的addPart((中传递arrayList的值
我很高兴回答你的问题。
if(result.contains("{")||result.contains("[")){
// pass JSON data
} else {
// Dealing with errors
}
我希望这能帮助你。