I’m trying to upload a file with Apache’s HTTP Client and MultipartRequests, but it gives me an error, here’s my code:
PostMethod filePost = new PostMethod("http://host/some_path");
Part[] parts = {
new StringPart("param_name", "value"),
new FilePart(f.getName(), f)
};
filePost.setRequestEntity(
new CountingMultipartRequestEntity(parts, filePost.getParams())
);
HttpClient client = new DefaultHttpClient();
int status = client.executeMethod(filePost);
It says “Cannot find symbol executeMethod()”.
It’s strange because I based my code on examples I found on Internet, and when I copy/paste their code, it shows me errors!
You are using HtppClient 4.x (see
DefaultHttpClient) while the example code is based on HttpClient 3.x (seeHttpClient). The API has been changed completely between these versions.Just include HttpClient 4 on your CLASSPATH and get rid of version 3.