java 获取Authorization信息
1、直接获取(可用,不太推荐)
@PostMapping("getAuthorization")
public void getAuthorization(@RequestHeader("Authorization") String authorization){
System.out.println("Authorization = " + authorization);
}
2、通过Header获取(推荐)
@PostMapping("getAuthorizationByHearder")
public void getAuthorizationByHearder(@RequestHeader HttpHeaders headers){
System.out.println("Authorization = " + headers.get("Authorization"));
}
3、通过Servlet获取(推荐)
@PostMapping("getAuthorizationByServlet")
public void getAuthorizationByServlet(HttpServletRequest request){
System.out.println("Authorization = " + request.getHeader("Authorization"));
}
4、获取Cookie中的Authorization信息
public String getAuthorization(HttpServletRequest request) {
Cookie[] cookie = request.getCookies();
for (int i = 0; i < cookie.length; i++) {
Cookie cook = cookie[i];
if("Authorization".equalsIgnoreCase(cook.getName())){
authorization = cook.getValue();
break;
}
}
return authorization;
}