访问第三方接口带Authorization认证
第一种方式
HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add("Authorization", "Bearer " + getToken()); SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); RestTemplate client = new RestTemplate(requestFactory); HttpMethod method = HttpMethod.GET; httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(null, httpHeaders); ResponseEntity<String> response = client.exchange(url, method, requestEntity, String.class);
第二种方式
event = event.toBuilder().requestTime(time).sign(sign).build(); String jsonString = JSON.toJSONString(event); log.info("传输给关键小事的参数是[{}]", jsonString); Request request = new Request.Builder() .header("Content-Type", "application/json") .header(PARAM_APP_KEY, APP_KEY) .header(PARAM_SIGN, sign) .header("Authorization", getToken()) .header(PARAM_REQUEST_TIME, time + "") .post(RequestBody.create(null, jsonString)) .url(APPOINT_ATTENDANCE_URL) .build(); JSONObject res = JSON.parseObject(HTTPClient.sendBodyString(request));

浙公网安备 33010602011771号