我正在尝试进行HTTP POST调用以上传文件(并且还必须填写参数ex。title)到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
答案 0 :(得分:0)