RestTemplate发送get请求并携带请求头

//设置请求头
HttpHeaders headers = new HttpHeaders();
headers.add("X-Access-Token", huaWenToken);
//封装请求头
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
RestTemplate restTemplate = new RestTemplate();
//发送请求并返回JSONObject
JSONObject jsonObject = restTemplate.exchange("http://www.baidu.com", HttpMethod.GET, formEntity, JSONObject.class).getBody();
posted @ 2022-08-09 11:36  fxsen  阅读(1642)  评论(0编辑  收藏  举报