I am trying to make a HTTP POST call to upload a file (and also has to fill parameters ex. title) to restful web service:
This is what I tried to do:
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();
}
This is not working. I am not sure how to upload the file and add the parameters and make the call? I tried this using Java Http Client to upload file over POST but the ones he/she used is deprecated? I have httpcore 4.4 alpha jar