使用HttpClient3.1上传文件方法一:
public static String sendPostWithFile(File imageFile, String userId, String url){
org.apache.commons.httpclient.HttpClient httpclient=null;
PostMethod post=null;
String info="";
try {
httpclient = new org.apache.commons.httpclient.HttpClient();
httpclient.setConnectionTimeout(5000);
httpclient.setTimeout(5000);
post = new PostMethod(url);
// 通过以下方法可以模拟页面参数提交
Part[] parts = { new FilePart("image", imageFile),
new StringPart("userId", userId)};
post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
httpclient.executeMethod(post);
info = new String(post.getResponseBody(),"utf-8");
} catch (Exception e) {
e.printStackTrace();
}finally {