美文网首页
springboot跨域服务端解决

springboot跨域服务端解决

作者: 小芃同学 | 来源:发表于2019-11-19 10:54 被阅读0次
    import java.io.IOException;
    import javax.servlet.FilterChain;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.web.filter.OncePerRequestFilter;
    
    public class CrossDomainFilter extends OncePerRequestFilter {
        private final Logger log = LoggerFactory.getLogger(this.getClass());
        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            response.addHeader("Access-Control-Allow-Origin", "*");
    //      response.addHeader("Access-Control-Allow-Credentials", "true");
            response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
            response.addHeader("Access-Control-Allow-Headers","origin, content-type, accept, x-requested-with, authorization");
            filterChain.doFilter(request, response);
        }
    }
    

    相关文章

      网友评论

          本文标题:springboot跨域服务端解决

          本文链接:https://www.haomeiwen.com/subject/grlwictx.html