【发布时间】:2017-01-22 19:02:51
【问题描述】:
我有以下要求:
String url = "url to oauth_token";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
RestTemplate restTemplate = new RestTemplate();
String body = "grant_type=authorization_code&client_id=123&client_secret=123&"
+ "redirect_uri=https://axyz.com&code=123";
HttpEntity<Object> entity = new HttpEntity<>(body, headers);
Object token = restTemplate.exchange(url, HttpMethod.POST, entity, Object.class);
这似乎返回 400(错误请求)。我也尝试过它的替代方案,其中 body 是 MultiValueMap 但这对我来说最有意义。我尝试请求的方式有问题吗?
【问题讨论】:
标签: spring spring-boot resttemplate