【问题标题】:RestTemplate Exception thrown when Authorization header begins with “Bearer”当 Authorization 标头以“Bearer”开头时引发 RestTemplate 异常
【发布时间】:2017-11-26 01:13:21
【问题描述】:

任何其他字符串都适用于 Authorization 标头,除了带有“bearer”的任何内容。下面是抛出的异常以及 RestTemplate 的代码 sn-p

 org.springframework.http.HttpHeaders httpHeaders = new org.springframework.http.HttpHeaders();
    httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);        
    httpHeaders.set("Authorization", "Bearer a3aae4e7-c612-47ef-be80-9af3d928d553");
    httpHeaders.add("Accept", "*/*");
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.add("display_name", "first.last@example.com");
    HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, httpHeaders);
    ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, request, String.class);

例外:

org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:66) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]

【问题讨论】:

    标签: spring rest oauth oauth-2.0 resttemplate


    【解决方案1】:

    问题是我的 OAuth 服务器无法解析不记名令牌,因为它无法从错误的连接字符串连接到数据库。

    【讨论】:

      猜你喜欢
      • 2020-10-25
      • 2020-06-10
      • 2021-09-30
      • 2017-09-07
      • 2019-04-29
      • 2019-12-31
      • 2021-01-17
      • 1970-01-01
      • 2011-11-04
      相关资源
      最近更新 更多