restTemplate.postForObject添加header

public static ObjectRestResponse sendMessage(WxTemplateMessageVo wxTemplateMessageVo) throws IOException, URISyntaxException {
        RestTemplate restTemplate = new RestTemplate();
        //设置header信息
        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setContentType(MediaType.APPLICATION_JSON);
        //随机数
        String nonce = String.valueOf((new Date()).getTime());
        String created = "1";
        String systemId = "1700";
        requestHeaders.add("digest",DigestUtil.getDigest(nonce,created,systemId));
        HttpEntity requestEntity =new HttpEntity(wxTemplateMessageVo,requestHeaders);
        ObjectRestResponse<Result> objectRestResponse = restTemplate.postForObject(sendMessageUrl, requestEntity, ObjectRestResponse.class);
        return objectRestResponse;
    }

参考文献:https://www.cnblogs.com/hujunzheng/p/6018505.html

你可能感兴趣的:(JAVA)