Skip to content

Java Springboot HandlerInterceptorAdapter 无法获取requestHeader

zeze.li edited this page Apr 14, 2021 · 1 revision

处理一下OPTIONS请求即可

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        if (request.getMethod().equals(RequestMethod.OPTIONS.name())) {
            response.setHeader("Access-control-Allow-Origin", request.getHeader("Origin"));
            response.setHeader("Access-Control-Allow-Methods", request.getMethod());
            response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"));
            response.setStatus(HttpStatus.OK.value());
            return true;
        }

        String accessToken = request.getHeader("Authorization");
        return JwtToken.verifyToken(accessToken);
    }

自定义边栏是什么东西

Clone this wiki locally