【问题标题】:Cross-Origin Request Blocked with CORS headers present存在 CORS 标头的跨域请求被阻止
【发布时间】:2016-01-21 23:07:58
【问题描述】:

在服务器端,我在 apache 中有以下过滤器,默认情况下允许所有方法和所有来源

<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

使用 angular $http 一篇文章正在运行,但另一篇文章失败了。失败的请求与同一个 apache 上的另一个应用程序对话。

Cross-Origin Request Blocked: The Same Origin Policy disallows 
reading the remote resource at http://localhost:.. 
(Reason: CORS header 'Access-Control-Allow-Origin' 
does not match 'http://localhost:8100, http://localhost:8100').

但响应头确实包含 ACAO

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
access-control-allow-credentials: true, true
access-control-allow-origin: http://localhost:8100, http://localhost:8100
Vary: Origin
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 22 Oct 2015 04:35:29 GMT

http://localhost:8100,http://localhost:8100”从何而来?你认为这是 angular $http 还是 Apache 问题?

【问题讨论】:

    标签: angularjs apache cross-domain httprequest


    【解决方案1】:

    Access-Control-Allow-Origin 接受 '*'single 来源作为其值。您不能在此处放置逗号分隔的列表。

    浏览器正在匹配原点(http://localhost:8100http://localhost:8100, http://localhost:8100 匹配,但未找到匹配项。

    你之前也遇到过类似的问题。看起来您正在运行代码以两次插入 CORS 标头。

    【讨论】:

    • 我没有放在那里,它来自服务器。你觉得我应该看看服务器配置?
    • 您的意思是在服务器端插入了两次标头?
    • 每个 CORS 标头的值都是重复的,所以看起来像这样。
    猜你喜欢
    • 2020-08-16
    • 2015-10-01
    • 2021-10-03
    • 2016-12-21
    • 2016-04-02
    • 1970-01-01
    • 2019-09-10
    • 2016-03-15
    相关资源
    最近更新 更多