学无先后,达者为师

网站首页 编程语言 正文

RestTemplate的post使用,token调用

作者:自由_free 更新时间: 2022-05-11 编程语言

RestTemplate的post使用

        MokaJobVM mokaJobVM = restTemplate.postForObject(url, entity, MokaJobVM.class);

url为路径,entity为请求体,包括请求头,第三个参数为响应参数

String apiKey = “gdfgfdgfdgdfgdf”;

    HttpHeaders headers = new HttpHeaders();
    headers.set("authorization", "Basic " + Base64.getEncoder().encodeToString(apiKey.getBytes()));


    MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
    headers.setContentType(type);

    HttpEntity entity = new HttpEntity(JacksonUtil.to(params), headers);

调用posy接口一定要在请求头设置Type

exchange的调用方式
ResponseEntity exchange = restTemplate.exchange(url, HttpMethod.POST, entity, MokaJobVM.class);

原文链接:https://blog.csdn.net/weixin_49194846/article/details/120038207

栏目分类
最近更新