java.net.HttpRetryException: cannot retry due to server authentication, in streaming mode访问令牌获取代码:
private String getAccessToken() throws Exception {
String urlString = "/oauth/token";
HttpEntity<MultiValueMap<String, String>> request = getAccessTokenRequest();
ResponseEntity<JSONObject> responseEntity = restTemplate
.exchange(urlString, HttpMethod.POST, request, JSONObject.class);
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
JSONObject userJson = responseEntity.getBody();
assertNotNull(userJson.get("access_token"));
assertEquals("bearer", userJson.get("token_type"));
return userJson.getString("access_token");
}
private HttpEntity<MultiValueMap<String, String>> getAccessTokenRequest() {
HttpHeaders headers = new HttpHeaders();
headers = setBasicAuthHeaders(headers);
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
MultiValueMap<String, String> requestMap = new LinkedMultiValueMap<>();
requestMap.add("grant_type", "client_credentials");
return new HttpEntity<>(requestMap, …Run Code Online (Sandbox Code Playgroud)