【问题标题】:Laravel Access to XMLHttpRequest at from origin has been blocked by CORS policyLaravel 对来自源的 XMLHttpRequest 的访问已被 CORS 策略阻止
【发布时间】:2019-08-20 05:19:59
【问题描述】:

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

从 'http://localhost:8083/api/login_otp' 访问 XMLHttpRequest 来源 'http://localhost:4200' 已被 CORS 策略阻止: Access-Control-Allow-Headers 不允许请求标头字段 ip 在预检响应中。

我找到了解决方案,并在 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 cross-origin-read-blocking


    【解决方案1】:

    阅读错误信息:

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

    上面写着ip是不允许的。

    看看你的代码:

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

    你的代码没有提到ip

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

    【讨论】:

      猜你喜欢
      • 2019-04-28
      • 2022-08-14
      • 2019-12-18
      • 2021-10-11
      • 2020-05-05
      • 2021-01-14
      • 1970-01-01
      • 2020-03-12
      相关资源
      最近更新 更多