不允许使用 Gulp、Restangular、Java EE 和 Wildfly 8 访问 Origin 'http://localhost:8888'
Origin 'http://localhost:8888' is not allowed access with Gulp, Restangular, Java EE and Wildfly 8
Restangular 在 post() 或 get() 上运行良好,但如果我想删除某些内容,则会出现以下错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8888' is therefore not allowed
access.
我试过这个网站上的解决方案:
How to enable Cross domain requests on JAX-RS web services?
@Provider
public class CORSFilter implements ContainerResponseFilter {
@Override
public void filter(final ContainerRequestContext requestContext,
final ContainerResponseContext cres) throws IOException {
cres.getHeaders().add("Access-Control-Allow-Origin", "*");
cres.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
cres.getHeaders().add("Access-Control-Allow-Credentials", "true");
cres.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
cres.getHeaders().add("Access-Control-Max-Age", "1209600");
}
}
但是我得到了以下错误:
The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:8888, *', but only one is allowed. Origin
'http://localhost:8888' is therefore not allowed access.
我不太明白这个错误是什么意思,我该如何解决?谢谢!
localhost:8888定义在Gulp中。
'Access-Control-Allow-Origin' header 必须是 'http://localhost:8888'
在帖子的第二个回答中解释的很好:
Why is jquery's .ajax() method not sending my session cookie?
我们在 web.xml 中添加了这些代码,它解决了问题:
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, POST, HEAD, PUT, DELETE</param-value>
</init-param>
Restangular 在 post() 或 get() 上运行良好,但如果我想删除某些内容,则会出现以下错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8888' is therefore not allowed access.
我试过这个网站上的解决方案:
How to enable Cross domain requests on JAX-RS web services?
@Provider
public class CORSFilter implements ContainerResponseFilter {
@Override
public void filter(final ContainerRequestContext requestContext,
final ContainerResponseContext cres) throws IOException {
cres.getHeaders().add("Access-Control-Allow-Origin", "*");
cres.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
cres.getHeaders().add("Access-Control-Allow-Credentials", "true");
cres.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
cres.getHeaders().add("Access-Control-Max-Age", "1209600");
}
}
但是我得到了以下错误:
The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:8888, *', but only one is allowed. Origin 'http://localhost:8888' is therefore not allowed access.
我不太明白这个错误是什么意思,我该如何解决?谢谢!
localhost:8888定义在Gulp中。
'Access-Control-Allow-Origin' header 必须是 'http://localhost:8888'
在帖子的第二个回答中解释的很好:
Why is jquery's .ajax() method not sending my session cookie?
我们在 web.xml 中添加了这些代码,它解决了问题:
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, POST, HEAD, PUT, DELETE</param-value>
</init-param>