天天看点

springboot的restTemplate发送参数为json的post请求

String json="{\"pageSize\":10,\"pageNumber\":1}";
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<String> request = new HttpEntity<>(json, headers);
        String res = this.restTemplate.postForObject("https://myurl", request ,String.class);
        System.out.println(res);