1、引入相关的jar包
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.3</version>
</dependency>
2、实现类
public void moveWaterMark(File file) {
try {
if (file.exists()) {
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://192.168.3.106:8888/upload");
MultipartEntity entity = new MultipartEntity();
entity.addPart("file", new FileBody(file));
httpPost.setEntity(entity);
HttpResponse response = client.execute(httpPost);
HttpEntity responseEntity = response.getEntity();
String result = EntityUtils.toString(responseEntity);
System.out.println(result);
}
} catch (Exception e) {
e.printStackTrace();
}
}