gpt4 book ai didi

apache - CORS 过滤器 tomcat 7 请求的资源上不存在 'Access-Control-Allow-Origin' header

转载 作者:行者123 更新时间:2023-12-04 15:34:01 25 4
gpt4 key购买 nike

我在我的 tomcat7 conf/web.xml 中使用以下配置

<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 网络服务器向 tomcat rest api 发送请求。 APache 网络服务器在 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 的请求 header :
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”

我究竟做错了什么?我错过了什么吗?

最佳答案

我自己找到了解决方案。 Apache Tomcat 包括对 CORS 的支持 - 从 Tomcat 版本 7.0.41 开始 - 我的问题是我通过在 ubuntu 12.04 版本上使用 apt-get install tomcat7 安装了 tomcat 7,并且它安装了比 7.0.41 更旧的版本。一旦我手动安装了 tomcat 7.0.54,cors 过滤器就起作用了

关于apache - CORS 过滤器 tomcat 7 请求的资源上不存在 'Access-Control-Allow-Origin' header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24285241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com