Sur*_*rez 2 java httpclient apache-httpcomponents
我使用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);
Run Code Online (Sandbox Code Playgroud)
帮助感谢!
谢谢,Surez
您可以使用以下FileBody构造函数设置文件名.
public FileBody(File file,
String filename,
String mimeType,
String charset)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1838 次 |
| 最近记录: |