Java解决options预请求不通过

@Component
public class SimpleCORSFilter implements Filter {
 
    private static final Logger log = Logger.getLogger(SimpleCORSFilter.class);
 
    @Override
    public void destroy() {
        // TODO Auto-generated method stub
 
    }
 
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
 
    }
 
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletResponse res = (HttpServletResponse) response;
        HttpServletRequest ret = (HttpServletRequest) request;
        // http: localhost:3000 http://114.215.30.117:8000
        res.setHeader("Access-Control-Allow-Origin", ret.getHeader("Origin"));
        // res.setHeader("Access-Control-Allow-Origin", "*");
        res.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        res.setHeader("Access-Control-Max-Age", "3600");
 
        res.setHeader("Access-Control-Allow-Headers", "Origin,Content-Type,token,tokenid");
        res.setHeader("Access-Control-Allow-Credentials", "true");
        res.setHeader("mode", "no-corred");
        chain.doFilter(request, response);
    }
 
 
}

 

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页