Talk is cheap show you code
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
MediaType mediaType = MediaType.MULTIPART_FORM_DATA;
// 设置请求的格式类型
headers.setContentType(mediaType);
MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
form.add("file", new FileUrlResource("D:\\doc\\yw\\test2.html"));
RequestCallback requestCallback = restTemplate.httpEntityCallback(new HttpEntity<>(form, headers));
File res = restTemplate.execute(
"https://baidu.com",
HttpMethod.POST,requestCallback,clientHttpResponse -> {
File ret = new File("res.html");
InputStream body = clientHttpResponse.getBody();
System.out.println(body.available());
StreamUtils.copy(body, new FileOutputStream(ret));
return ret;
});