:我们有一个节点快递web服务器(UI),要求从Java Dropwizard(新泽西州)服务器的HTTP API,在同一台主机上运行。CORS与我在使用基本的HTTP认证与CORS一些问题基本HTTP认证
的API保护与HTTP基本身份验证,并且我特地来实现我的球衣服务器上的以下过滤器(从这个职位采取:How to handle CORS using JAX-RS with Jersey):
@Provider
public class CORSFilter implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext request,
ContainerResponseContext response) throws IOException {
response.getHeaders().add("Access-Control-Allow-Origin", "http://localhost:9000");
response.getHeaders().add("Access-Control-Allow-Headers",
"Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
response.getHeaders().add("Access-Control-Allow-Credentials", "true");
response.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
}
}
然而,当我尝试加载我的控制台给我以下输出:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9000/intraday/parameters. (Reason: CORS header ‘Access-Control-Allow-Origin’ does not match ‘http://localhost:9000’)
我无法理解这个错误。显然,起源是相同的(http://localhost:9000),所以我不知道为什么它不匹配。
我也确信,任何预检OPTIONS请求回答HTTP代码200
也许这可能会帮助你:https://stackoverflow.com/questions/28065963/how-to-handle-cors-using-jax-rs-with-jersey – sascha10000
@ sascha10000你提供的链接是相同的职位我已经链接到我的问题。 –
噢,对不起,我真的没有看到,这是一个链接... – sascha10000