Lan*_*yen 7 tomcat xmlhttprequest cors
我有一个启用了CORS的tomcat 8服务器web.xml.CORS插件适用于大多数情况,但有时会混合来自本地主机和服务器主机的头请求
XMLHttpRequest cannot load http://mipldevlinux7:6060/juneberry/data/blue-marbles/config.json. The 'Access-Control-Allow-Origin' header has a value 'http://localhost:3000' that is not equal to the supplied origin. Origin 'http://mipldevlinux7:7777' is therefore not allowed access
Run Code Online (Sandbox Code Playgroud)
我的tomcat服务器在一个名为mipldevlinux7port的6060服务器上,我在端口上的同一主机上有一个生产服务器7777.
我正在进行开发localhost:3000,我的同事运行他的开发服务器localhost:8080.
我们收到了CORS错误,错误混合了我们的localhosts之间的标题3000,有时候也是如此8080.有时我们甚至会收到一个标题请求,mipledevlinux7:7777说明我们从localhost 请求的原因.
我正在使用的CORS是在CORS tomcat 8中构建的:
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,Last-Modified</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
</init-param>
<init-param>
<param-name>cors.support.credentials</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
是tomcat缓存请求标头还是以某种方式使用最后一个请求标头导致混淆,并阻止所有请求?
小智 0
如果设置cors.support.credentials为 true,则使用cors.preflight.maxage-1 禁用浏览器缓存:
<init-param>
<param-name>cors.preflight.maxage</param-name>
<param-value>-1</param-value>
</init-param>
Run Code Online (Sandbox Code Playgroud)
您确定要设置cors.allowed.origins为*吗?
| 归档时间: |
|
| 查看次数: |
717 次 |
| 最近记录: |