String filePath = ""; //File Path to set
String fileParam = ""; //Request parameter for file
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
client.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "utf-8");
try {
MultipartEntity entity = new MultipartEntity();
File file = new File(filePath);
ContentBody fileBody = new FileBody(file); // file
entity.addPart(fileParam, fileBody);
httpPost.setEntity(entity);
HttpResponse response = client.execute(httpPost);
if (response.getStatusLine().getStatusCode() == 200) { // 成功
//HttpEntity responseEntity = response.getEntity();
Log.i("TAG", "SUCCESSED");
} else {
Log.i("TAG", "FAILED");
}
} catch (Exception e) {
Log.e("TAG", "EXCEPTION");
}
String filePath = ""; //File Path to set
String fileParam = ""; //Request parameter for file
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
client.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "utf-8");
try {
MultipartEntity entity = new MultipartEntity();
File file = new File(filePath);
ContentBody fileBody = new FileBody(file); // file
entity.addPart(fileParam, fileBody);
httpPost.setEntity(entity);
HttpResponse response = client.execute(httpPost);
if (response.getStatusLine().getStatusCode() == 200) { // 成功
//HttpEntity responseEntity = response.getEntity();
Log.i("TAG", "SUCCESSED");
} else {
Log.i("TAG", "FAILED");
}
} catch (Exception e) {
Log.e("TAG", "EXCEPTION");
}