我正在尝试将请求发布到休息服务(https)。 尽管RestTemplate.exchange总是返回401-未经授权,但在邮递员中一切正常。 正文和标题相同。
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("client_id", clientId);
httpHeaders.add("api_key", authToken);
// httpHeaders.add("Authorization", "Basic " + authToken); - also tried
HttpEntity<?> requestEntity = new HttpEntity<>(request, httpHeaders);
return restTemplate.exchange(getUrl(), httpMethod, requestEntity, responseType).getBody();
我尝试跳过ssl验证,也尝试过以下解决方案:Spring Boot RestTemplate Basic Authentication using RestTemplateBuilder,这无济于事。 有什么想法我想念的吗?