@Service
@RequiredArgsConstructor
public class OpenApiService {
private final RestTemplate restTemplate;
@Value("${kakao.apiKey}")
private String kakaoKey;
public void getToken(String code){
HttpHeaders headers = new HttpHeaders();
headers.add("Content-type", "application/x-www-form-urlencoded;charset=utf-8");
JSONObject body = new JSONObject();
body.put("grant_type","authorization_code");
body.put("client_id", kakaoKey);
body.put("redirect_uri","http://localhost:8080/openapi/kakao");
body.put("code",code);
LoginResponseDto loginResponseDto = restTemplate.postForObject("https://kauth.kakao.com/oauth/token", new HttpEntity<>(body.toString(),headers), LoginResponseDto.class);
}
}
자바 스프링 사용하고 있습니다.
There was an unexpected error (type=Internal Server Error, status=500).
401 Unauthorized: [no body]
org.springframework.web.client.HttpClientErrorException$Unauthorized: 401 Unauthorized: [no body]
이 에러가 계속 발생하는데 왜그럴까요…
code는 제대로 가져오는데 토큰가져오는곳에서 에러가 발생하는거 같습니다.