我能够从邮递员成功触发发帖请求,但是使用springboot RestTemplate我遇到了401未经授权的错误。请在我的代码下面找到我没弄错的地方
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36");
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.add("Accept", "application/json");
JSONObject jsonObject =new JSONObject();
jsonObject.put("client_id", "h_admin");
jsonObject.put("client_secret", "*********");
jsonObject.put("grant_type", "client_credentials");
jsonObject.put("token_format", "opaque");
HttpEntity<String> request = new HttpEntity<String>(jsonObject.toString(), headers);
HttpEntity<Object> response = restTemplate.exchange("https://test.com/oauth/token", HttpMethod.POST,request,Object.class);
System.out.println(response.toString());
System.out.println(response.getHeaders());