慕哥6287543
如果我很了解你,你需要发布另一个带有凭据的网络API,你可以使用RestTemplate 就像下面的例子 public List<EtisAccount> getAllActiveAccount(){ logger.debug("Debug: in Class \t"+this.getClass().getName()+" Method Name is: \t"+new Object() {}.getClass().getEnclosingMethod().getName()); Properties sprinklrProp=sprinklrProperties.getSprinklrKeys(); SprinklrCredential sprinklrCredential=credentialBuilder.getSprinklrCredential(); RestTemplate restTemplate= new RestTemplate(); HttpHeaders header = new HttpHeaders(); header.setBearerAuth(sprinklrCredential.getAccess_token()); header.add("key", sprinklrCredential.getApi_key()); header.set("Accept", MediaType.APPLICATION_JSON_UTF8_VALUE); UriComponentsBuilder uriBuilder= UriComponentsBuilder.fromUriString(sprinklrProp.getProperty("sprinlrUri").toString()) .queryParam("types", sprinklrProp.getProperty("accountTypes").toString()); HttpEntity<String> entity= new HttpEntity<>(header); sslCertificateValidation.disable(); ResponseEntity<String> sprinklrResponse=restTemplate.exchange(uriBuilder.toUriString(),HttpMethod.GET,entity, String.class); List<EtisAccount> activeAccouts=etisAccountHelper.getAllSocialEtisAccounts(sprinklrResponse.getBody()); logger.debug(String.valueOf(sprinklrResponse.getStatusCodeValue())); logger.debug(activeAccouts.toString()); return activeAccouts; }这是使用 RestTemplate 调用在线 API 的示例在这里我用凭据构建标头(不记名身份验证) HttpHeaders header = new HttpHeaders(); header.setBearerAuth(sprinklrCredential.getAccess_token()); header.add("key", sprinklrCredential.getApi_key()); header.set("Accept", MediaType.APPLICATION_JSON_UTF8_VALUE);在这里我添加标头 requestEntity 以添加到 Resttemplate 请求 HttpEntity<String> entity= new HttpEntity<>(header);在这里我使用交换方法得到响应 ResponseEntity<String> sprinklrResponse=restTemplate.exchange(uriBuilder.toUriString(),HttpMethod.POST,entity, String.class);