赞
踩
``` @Autowired RestTemplate restTemplate; @PostMapping("/send") public TopicFileResponse send(String url,String path) { HttpHeaders headers = new HttpHeaders(); MediaType type = MediaType.parseMediaType("multipart/form-data"); // 设置请求的格式类型 headers.setContentType(type); FileSystemResource fileSystemResource = new FileSystemResource(path); MultiValueMap<String, Object> form = new LinkedMultiValueMap<>(); form.add("name", fileSystemResource); HttpEntity<MultiValueMap<String, Object>> files = new HttpEntity<>(form, headers); ResponseEntity<TopicFileResponse> responseResponseEntity = restTemplate.postForEntity(url, files, TopicFileResponse.class); TopicFileResponse body = responseResponseEntity.getBody(); return body; } ``` > 其中TopicFileResponse是对方请求该返回的结果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。