跨域访问(cors) access-control-allow-origin 多个域名

1.首先要了解问什么访问要跨域
2.配置多个作用访问

资源文件中修改app.allowOrigin = http:XXX,HTTP:kkk,..
或者app.allowOrigin = * 这种相对来说风险极大


    public void doFilter(ServletRequest servletRequest,
            ServletResponse servletResponse, FilterChain filterChain)
                    throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        HttpSession session = request.getSession();

        if ("true".equals(PropertiesUtils.getProperty("app.debug"))) {
            // 允许跨域访问
            response.setHeader("Access-Control-Allow-Origin",
                    PropertiesUtils.getProperty("app.allowOrigin"));
            response.setHeader("Access-Control-Allow-Headers",
                    "Origin, X-Requested-With, Content-Type, Accept, Cookie");
            response.setHeader("Access-Control-Allow-Methods",
                    "GET, POST, PUT, DELETE, OPTIONS");
            response.setHeader("Access-Control-Allow-Credentials", "true");
        }
    }
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Minco_Tse/article/details/51542250
文章标签: 跨域访问-cors
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

跨域访问(cors) access-control-allow-origin 多个域名

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭