取自该站点上的示例,我认为通过填写标头值并将标头传递给模板,这将是最自然的方法。
这是为了填写标题
Authorization:
String plainCreds = "willie:p@ssword";byte[] plainCredsBytes = plainCreds.getBytes();byte[] base64CredsBytes = base64.enprebase64(plainCredsBytes);String base64Creds = new String(base64CredsBytes);HttpHeaders headers = new HttpHeaders();headers.add("Authorization", "Basic " + base64Creds);
这是将标头传递给REST模板:
HttpEntity<String> request = new HttpEntity<String>(headers);ResponseEntity<Account> response = restTemplate.exchange(url, HttpMethod.GET, request, Account.class);Account account = response.getBody();
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)