【发布时间】:2014-08-29 22:00:38
【问题描述】:
我正在尝试进行 HTTP POST 调用以将文件(并且还必须填写参数,例如标题)上传到 RESTful Web 服务:
这是我尝试做的:
File file = new File(filepath);
HttpClient client = new DefaultHttpClient(); //DefaultHTTPClient is deprecated?
HttpPost post = new HttpPost(url);
//Multipart Entity is also deprecated??
MultipartEntity entity = new MultipartEntity();
entity.addPart("file[path]", new FileBody(file));
post.setEntity((HttpEntity) entity);
try {
HttpResponse response = client.execute(post);
} catch (IOException e) {
e.printStackTrace();
}
这不起作用。我不确定如何上传文件并添加参数并进行调用?我使用Java Http Client to upload file over POST 尝试过这个,但他/她使用的那些已被弃用?我有 httpcore 4.4 alpha jar
【问题讨论】:
标签: java apache-commons-httpclient