一、postForObject方法(含请求头)
MultiValueMap<String, Object> para = new LinkedMultiValueMap<>();//非请求头参数 路径参数(body参数) para.add("SFCODE", sfcode); para.add("PAGE_NO", pageNo); para.add("PAGE_SIZE", pageSize); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("ACTION","RP001");//自定义header参数 HttpEntity<MultiValueMap> requestEntity =new HttpEntity<MultiValueMap>(para, requestHeaders); String result = restTemplate.postForObject("http://ip:port/test/method", requestEntity, String.class); System.out.print(result);