티스토리 뷰
bearer token 발급 후 사용자정보를 체크할 때 사용한다.
public static void userChk (HttpServletRequest request, String token) {
Map<String, Object> returnList = new HashMap<String,Object>();
HttpSession session = request.getSession();
try{
URL url = new URL({URL});
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization","Bearer " + token);
conn.setRequestProperty("Content-Type","application/json");
conn.setRequestMethod("POST");
try(BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))){
String output;
StringBuffer sb = new StringBuffer();
while ((output = in.readLine()) != null) {
sb.append(output).append("\n");
}
if(!sb.equals("")){
returnList = new ObjectMapper().readValue(sb.toString(), new TypeReference<Map<String, Object>>(){});
}
}catch (Exception e) {
e.printStackTrace();
}
}catch (Exception e){
System.out.println("사용자정보가 없습니다");
e.printStackTrace();
}
}
'Development > JAVA' 카테고리의 다른 글
[JAVA] JWT decode (0) | 2021.11.10 |
---|---|
[JAVA] Http POST urlencoded (0) | 2021.08.24 |
[JAVA] URL 한글 인코딩 (0) | 2021.08.20 |
[JAVA] 페이징 pageable example (without jpa) (0) | 2021.08.20 |
[JAVA] ElasticSearch 키워드 검색 (0) | 2021.08.11 |
댓글
링크
최근에 올라온 글
- Total
- Today
- Yesterday