RestTemplate client = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); //定义请求参数类型,这里用json所以是MediaType.APPLICATION_JSON headers.setContentType(MediaType.MULTIPART_FORM_DATA); // Map<String, Object> map = new HashMap<String, Object>(); // map.put("infohash", "1111111"); // map.put("name", "肖申克的救赎12"); // map.put("id", 111111); // map.put("size", 111111); //HttpEntity<Map<String, Object>> request = new HttpEntity<Map<String, Object>>(map, headers); MultiValueMap<String,Object> params = new LinkedMultiValueMap<>(); params.add("infohash",infohash.getInfoHash()); params.add("name", infohash.getName()); params.add("id", infohash.getId()); params.add("size", infohash.getLength()); ResponseEntity<String> entity = client.postForEntity("http://localhost:9527/magnet/infohash/setdata", params, String.class); //获取3方接口返回的数据通过entity.getBody();它返回的是一个字符串; String body = entity.getBody();