小编bri*_*ton的帖子

CORS 预检通道未成功。仅在 Firefox 中。铬工作正常

所以我有一个不寻常的问题,我不确定如何进行调试。我有一个 angular 4 应用程序,它在服务器端使用 cakephp。

在我的应用程序中,我有许多不同的屏幕,我可以正常访问,除了一个并且它只是 Firefox 的一个问题。如果我使用chrome,我可以打开它。我在 Firefox 中收到以下警告

跨域请求被阻止:同源策略不允许读取位于http://localhost:8080/api/cross-series/network-series的远程资源 。(原因:CORS 预检通道没有成功)。

这是我用来导航到屏幕的链接

<div class = "col-xs-4 col-sm-4 col-md-4 col-lg-4"  [routerLink]="['/dashboards/cross-series/network',{networkId:3}]">

            <img src = "assets/img/networks/com-circle.png" class = "cross-series-navigation-icon clickable"
                 alt = "Com"/>

        </div>
Run Code Online (Sandbox Code Playgroud)

然后在 php 中,我有以下 Cors 代码

        $this->response->header('Access-Control-Allow-Origin', 'http://localhost:4200');
//  $this->response->header('Access-Control-Allow-Origin', 'http://localhost:8066');
        $this->response->header('Access-Control-Allow-Credentials', 'true');
        $this->response->header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, DELETE');
        $this->response->header('Access-Control-Allow-Headers', 'Origin, Authorization, X-Requested-With, Content-Type, Accept, Cache-Control');

        header_remove('X-Powered-By'); //remove default PHP header

        array_push($this->allowedActions, 'options');


        CakeLog::debug("This is the action: " . print_r($this->action, true), 'debug');
Run Code Online (Sandbox Code Playgroud)

在日志中,我可以看到 Firefox 和 Chrome …

php firefox cakephp cakephp-routing angular

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

angular ×1

cakephp ×1

cakephp-routing ×1

firefox ×1

php ×1