2 qq 15861469 qq_15861469 于 2016.04.23 16:40 提问

Android 用MultipartEntity上传图片,需要一个token字段验证,如何实现

public static String uploadBitmap(File file) {
HttpPost httpPost = new HttpPost(ApiUtils.uploadBitmap);
DefaultHttpClient httpClient = new DefaultHttpClient();
MultipartEntity MultipartEntity=new MultipartEntity();
ContentBody contentBody=new FileBody(file);
MultipartEntity.addPart("photo", contentBody);

// MultipartEntity.addPart("_token", );
/* List list=new ArrayList();
list.add(new BasicNameValuePair("_token",MyAppcation.token));*/
// list.add(new BasicNameValuePair("photo",MultipartEntity.toString()));
/* List params = new ArrayList();
params.add(new BasicNameValuePair("photo", ));
params.add(new BasicNameValuePair("_token", MyAppcation.token));*/
if (MyAppcation.cookieStore != null) {
httpClient.setCookieStore(MyAppcation.cookieStore);
}
HttpResponse response = null;
try {
httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
response = httpClient.execute(httpPost);
String json = EntityUtils.toString(response.getEntity());
if (json.isEmpty()) {
return json;
} else {
return "获取失败";
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!