Java - Access-Control-Allow-Origin 多源域? [英] Java - Access-Control-Allow-Origin Multiple Origin Domains?

查看:30
本文介绍了Java - Access-Control-Allow-Origin 多源域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经阅读了有关此问题的其他线程,但没有找到解决方案.

So I have read through the other threads regarding this and have not found a solution.

我遇到的问题是因为我设置了access-control-allow-methods"true"我不能使用 setHeader("Access-Control-Allow-Origin", "*");

The problem Im having is because im setting "access-control-allow-methods" "true" I cant use setHeader("Access-Control-Allow-Origin", "*");

我需要设置两个特定的域...任何帮助表示赞赏.

I need to set two specific domains...any help is appreciated.

推荐答案

public class CorsInterceptor implements ContainerResponseFilter {
    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
            throws IOException {
        //Cuando se envia la cookie http-only el header 'Access-Control-Allow-Origin' no puede ser *
        responseContext.getHeaders().putSingle("Access-Control-Allow-Origin", requestContext.getHeaderString("origin"));
    }
}

这篇关于Java - Access-Control-Allow-Origin 多源域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆