PostMethod filePost = new PostMethod(url) ;
HttpClient client = new HttpClient();
try {
//Part[] parts = new Part[] { new CustomFilePart(fileName, file),
Part[] parts = new Part[] { new CustomFilePart(material_code, file),
new StringPart(“item_code”,item_code,”GBK”),//
};
filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
int status = client.executeMethod(filePost);
byte[] bytes = filePost.getResponseBody();//返回的结果
result = new String(bytes);
if (status == HttpStatus.SC_OK) {
System.out.println("上传成功");
} else {
System.out.println("上传失败");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
filePost.releaseConnection();
((SimpleHttpConnectionManager)client.getHttpConnectionManager()).shutdown();
}