[英]oauth2 client in Spring Boot
This question is based on the solution in this thread .I implemented the top answer, but I am getting mixed results. 这个问题基于该线程中的解决方案。我实现了最佳答案,但结果不尽相同。
String stringObj = restTemplate.getForObject(http://server/rest/api/users?access_token=991949410990808314, String.class);
In code I am trying to hit a simple GET endpoint, but I am getting a 401 Unauthorized, but if I copy the rest url + token to my browser it returns the expected json object. 在代码中,我试图到达一个简单的GET端点,但得到了401 Unauthorized,但是如果我将其余的url +令牌复制到浏览器中,它将返回预期的json对象。 Anyone have a clue why?
有人知道为什么吗?
It is not because you need to put the "Authorization" in the headers and put in you rest call? 不是因为您需要在标题中放入“授权”,然后在您的rest调用中放入? Like
喜欢
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Basic " + base64Creds);
The problem I was having was with 我遇到的问题是
@Autowired
RestTemplate restTemplate;
The restTemplate was not getting injected as I thought. restTemplate没有像我想的那样被注入。 It worked when I just did:
我刚做的时候就奏效了:
RestTemplate restTemplate = new RestTemplate();
If anyone has any ideas why @Autowired is not working, I'd love to hear them. 如果有人对@Autowired为何不起作用有任何想法,我很乐意听到。 Thanks.
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.