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();
2
2
String body = null; RestTemplate client = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); MovihInfohashDto infohash = movihInfohashService.create(resources); if(infohash.getId() != null) { MultiValueMap<String,Object> params = new LinkedMultiValueMap<>(); params.add("infohash",infohash.getInfoHash()); params.add("name", infohash.getName()); params.add("id", infohash.getId().toString()); params.add("size", infohash.getLength().toString()); headers.add("Content-Type", "application/x-www-form-urlencoded"); ResponseEntity<String> entity = client.postForEntity(JbibUtils.SETDATA, params, String.class); //获取3方接口返回的数据通过entity.getBody();它返回的是一个字符串; body = entity.getBody(); } JSONObject jo = JSONObject.parseObject(body); if(jo != null) { if(jo.getInteger("code") == 1) { if(jo.getString("msg").equals("CREATED")) { return new ResponseEntity<>(HttpStatus.OK); } } } return new ResponseEntity<>(HttpStatus.NOT_EXTENDED);