嗨!我对spring-security + angular身份验证有问题

嗨!我对spring-security + angular身份验证有问题,第1张

嗨!我对spring-security + angular身份验证有问题

问题与CORS有关,您应该添加以下内容

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)        throws IOException, ServletException {    HttpServletRequest request = (HttpServletRequest) servletRequest;    System.out.println("CORSFilter HTTP Request: " + request.getMethod());    // Authorize (allow) all domains to consume the content    ((HttpServletResponse) servletResponse).addHeader("Access-Control-Allow-Origin", "*");    ((HttpServletResponse) servletResponse).addHeader("Access-Control-Allow-Methods","GET, OPTIONS, HEAD, PUT, POST");    HttpServletResponse resp = (HttpServletResponse) servletResponse;    // For HTTP OPTIONS verb/method reply with ACCEPTED status pre -- per CORS handshake    if (request.getMethod().equals("OPTIONS")) {        resp.setStatus(HttpServletResponse.SC_ACCEPTED);        return;    }    // pass the request along the filter chain    chain.doFilter(request, servletResponse);}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5621687.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存