大飞_dafei

导航

springboot 项目中_ 利用Filter去解决跨域问题

springboot 项目中_ 利用Filter去解决跨域问题

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {


        response.addHeader("Access-Control-Allow-Origin","*");
        // response.addHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE");
        response.addHeader("Access-Control-Allow-Methods","*");
        response.addHeader("Access-Control-Allow-Headers","Origin, Content-Type, Cookie, Accept, multipart/form-data, application/json");
        response.addHeader("Access-Control-Expose-Headers", "Authorization");
        response.addHeader("Access-Control-Max-Age","1800");

        chain.doFilter(request, response);
    }

 

posted on 2020-06-30 13:02  大飞_dafei  阅读(519)  评论(0编辑  收藏  举报