记得try,catch....................
妈的他们的什么
MultiValueMap<String, String[]> paramMap = new LinkedMultiValueMap<>();可把老子坑惨了
try { //复杂构造函数的使用 SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setConnectTimeout(10000);// 设置超时 requestFactory.setReadTimeout(10000); //利用复杂构造器可以实现超时设置,内部实际实现为 HttpClient RestTemplate restTemplate = new RestTemplate(requestFactory); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON_UTF8); String[] ids={"8a6980fa762870db01762886a3f50000","8a6980f87626a30601762790871e0002"}; //设置访问参数 HashMap<String, Object> params = new HashMap<>(); params.put("items", ids); String url = "http://ip:port/tDeviceInfo/getbyids"; //设置访问的Entity HttpEntity requestEntity = new HttpEntity<>(params, headers);//params 请求体内容, headers请求头内容 JSONObject jsonObject = iRestTemplate.postForObject(url, requestEntity, JSONObject.class); System.out.println(jsonObject); }catch (Exception e){ e.printStackTrace(); }