2
我使用Apache的HttpClient通过MultipartEntity上传文件,我需要上传不同的文件名的文件..下面是我的代码...设置自定义文件名
FileBody uploadFilePart = new FileBody(binaryFile);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("bin", uploadFilePart);
reqEntity.addPart("comment", comment);
httpPost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println("Response content length: " +
resEntity.getContentLength());
}
EntityUtils.consume(resEntity);
帮助感激!
感谢, Surez
It Works!非常感谢。 – Surez 2012-02-02 18:21:42
仅供参考在较新版本中不推荐使用该方法,但仍可以在构造函数中设置该名称。 – Amber 2016-02-29 19:12:58