发送一般的token使用下面这种即可:
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Accept", "application/json");
httpHeaders.add("Authorization", propertyUtils.getDeviceTreeToken());
String result = getRequest(propertyUtils.getDeviceTreeUrl(), null, httpHeaders);
private String getRequest(String url, MultiValueMap<String, String> params, HttpHeaders headers) throws Exception {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(0);// 设置建立连接超时时间
requestFactory.setReadTimeout(0);// 设置等待返回超时时间
RestTemplate client = new RestTemplate(requestFactory);
HttpMethod method = HttpMethod.GET;
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(params, headers);
ResponseEntity<String> response = client.exchange(url, method, requestEntity, String.class);
return response.getBody();
}
针对于Bearer token改下写法就行:
httpHeaders.add("Authorization", "Bearer " + propertyUtils.getDeviceTreeToken());
网友评论