RestTemplate的用法小记
程序员文章站
2022-06-26 15:30:38
...
第三方请求,用惯了feign,有点忘记了最基础的restTemplate,记录一下
//组装url
String url= OrgInfo.BASE_URL+"/"+OrgInfo.ORG_NAME+"/"+OrgInfo.APP_NAME+"/users";
//创建请求头
HttpHeaders headers = new HttpHeaders();
//Request Headers: {“Content-Type”:”application/json”}
headers.setContentType(MediaType.APPLICATION_JSON);
//设置token
headers.set("Authorization",TokenUtil.getAccessToken());
//创建请求对象 registerDTO业务对象
HttpEntity<RegisterDTO> requestEntity=new HttpEntity(registerDTO,headers);
//发送请求
restTemplate.postForObject(url,requestEntity,Object.class);