直接上代码--
public String HcUploadFile(String url, String filePath, String type) throws ClientProtocolException, IOException {
HttpPost post = new HttpPost(url);
File file = new File(filePath);
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpEntity entity = null;
HttpResponse response = null;
String BoundaryStr = "------------7da2e536604c8";
post.addHeader("Connection", "keep-alive");
post.addHeader("Accept", "*/*");
post.addHeader("Content-Type", "multipart/form-data;boundary=" + BoundaryStr);
post.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");
MultipartEntityBuilder meb = MultipartEntityBuilder.create();
meb.setBoundary(BoundaryStr).setCharset(Charset.forName("utf-8")).setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
meb.addBinaryBody("media", file, ContentType.APPL