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;
}