我正在使用以下配置在我的tomcat7 conf/web.xml文件中。
以下是来自 Chrome 的请求头部:
<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>
我的Apache Web服务器向Tomcat REST API发送请求。Apache Web服务器在端口8005上运行,而Tomcat在8080上运行。因此请求从mydomain.com:8085/index.php/kop发送到mydomain.com:8080/webiste-1.0/rest-api/product。我收到了:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://x.x.x.x:8085' is therefore not allowed access.
以下是来自 Chrome 的请求头部:
Accept:application/json, text/javascript, */*; q=0.01
Cache-Control:no-cache
Origin:http://x.x.x.x:8085
Pragma:no-cache
Referer:http://x.x.x.x:8085/html/index.php/kop_och_salj
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
响应头信息: 内容长度: "0" 日期: "2014年6月18日星期三12:02:11 GMT" 服务器: "Apache-Coyote/1.1"
我做错了什么?有什么我漏掉的吗?