Spring boot에서
String reqURL = "https://kapi.kakao.com/v1/user/unlink";
try {
URL url = new URL(reqURL);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", "KakaoAK " + adminKey);
conn.setRequestProperty("content-Type", "application/x-www-form-urlencoded");
conn.setDoOutput(true);
System.out.println(adminKey);
String body = "{ \"target_id_type\" : \"user_id\", \"target_id\" : \"" + user.getSocialId() + "\" }";
System.out.println(body);
try (OutputStream os = conn.getOutputStream()) {
byte request_data[] = body.getBytes("utf-8");
os.write(request_data);
os.close();
} catch (Exception e) {
e.printStackTrace();
}
int responseCode = conn.getResponseCode();
System.out.println("responseCode : " + responseCode);
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String result = "";
String line = "";
while ((line = br.readLine()) != null) {
result += line;
}
System.out.println(result);
} catch (IOException e) {
e.printStackTrace();
}
를 통해 연결 끊기를 시도하고 있지만
Server returned HTTP response code: 401 for URL: https://kapi.kakao.com/v1/user/unlink
에러가 발생하고 있습니다.
해결방법을 알고싶습니다