欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

RestTemplate 发送请demo

程序员文章站 2022-03-04 19:04:46
...
                            RestTemplate restTemplate = new RestTemplate();
                            MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
                            paramMap.add("msg","测试");
                            HttpHeaders headers = new HttpHeaders();
                            headers.setContentType(MediaType.APPLICATION_JSON);
                            headers.set("charset","utf-8");

                            HttpEntity httpEntity = new HttpEntity(paramsEncode,headers);
                            //HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(paramMap,headers);
                            ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
                            ResResultDto dto = ResResultDto.format(responseEntity.getBody());