Laravel来自源的XMLHttpRequest访问已被CORS策略阻止

问题描述 投票:-4回答:1

当我从Angular应用程序发送呼叫到Laravel时,我遇到了以下问题

Access to XMLHttpRequest at 'http://localhost:8083/api/login_otp' from origin 'http://localhost:4200' has been blocked by CORS policy: Request header field ip is not allowed by Access-Control-Allow-Headers in preflight response.

我找到了解决方案并做了以下更改

在CROS.php

public function handle($request, Closure $next)
    {
        return $next($request)
        ->header('Access-Control-Allow-Origin', '*') 
        ->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE, OPTIONS')
        ->header('Access-Control-Allow-Headers', 'Origin, Content-Type, X-Auth-Token, Authorization, X-Requested-With, x-xsrf-token');
    }

我在Access-Control-Allow-Headers中添加了x-xsrf-token仍然会遇到同样的问题

php angular laravel-5.2 cross-origin-read-blocking
1个回答
1
投票

阅读错误消息:

Access-Control-Allow-Headers不允许请求头字段ip

它说ip是不允许的。

看看你的代码:

'Origin, Content-Type, X-Auth-Token, Authorization, X-Requested-With, x-xsrf-token'

你的代码没有提到ip

ip添加到允许的标头列表中。

© www.soinside.com 2019 - 2024. All rights reserved.