简体   繁体   English

Laravel 从源访问 XMLHttpRequest 已被 CORS 策略阻止

[英]Laravel Access to XMLHttpRequest at from origin has been blocked by CORS policy

When I send a call from an Angular application to Laravel, I am getting the below issue当我从 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.从源 ' http://localhost:4200 ' 访问 XMLHttpRequest at ' http://localhost:8083/api/login_otp ' 已被 CORS 策略阻止:Access-Control-Allow-Headers 不允许请求标头字段 ip在飞行前响应中。

I found a solution and did the below changes in CROS.php我找到了一个解决方案并在 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');
    }

I added x-xsrf-token in Access-Control-Allow-Headers, but I am still getting the same error.我在 Access-Control-Allow-Headers 中添加了 x-xsrf-token,但我仍然遇到相同的错误。

Read the error message:阅读错误信息:

Request header field ip is not allowed by Access-Control-Allow-Headers Access-Control-Allow-Headers 不允许请求头字段 ip

It says ip is not allowed.它说ip是不允许的。

Look at your code:看看你的代码:

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

Your code doesn't mention ip .您的代码没有提到ip

Add ip to the list of allowed headers.ip添加到允许的标头列表中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 来自'http:// localhost / api from origin'http:// localhost:8000'的XMLHttpRequest访问已被CORS策略阻止 - Access to XMLHttpRequest at 'http://localhost/api from origin 'http://localhost:8000' has been blocked by CORS policy 已被 CORS 政策阻止:无“访问控制允许来源” - has been blocked by CORS policy: No 'Access-Control-Allow-Origin' 访问 abcd.com 上的字体已被 CORS 政策阻止:没有“访问控制允许来源” - Access to Font at abcd.com has been blocked by CORS policy: No 'Access-Control-Allow-Origin' PHP-CORS策略已阻止对字体的访问:没有“ Access-Control-Allow-Origin”标头 - PHP - Access to Font has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header 无法在React中使用GraphQL查询-已被CORS策略阻止:所请求的资源上不存在“ Access-Control-Allow-Origin”标头 - Cannot use GraphQL queries in React - has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource Flutter - XMLHttpRequest 已被 CORS 政策阻止 - Flutter - XMLHttpRequest has been bloked by CORS policy XAMPP 服务器已被 CORS 策略阻止: - XAMPP Server has been blocked by CORS policy: Laravel7 CORS:被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:否 'Access-Control-Allow-Origin' - Laravel7 CORS : blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' ReactJS-PHP GET请求已被CORS策略阻止 - ReactJS - PHP GET Request has been blocked by CORS policy 获取 wp_mail 已被 CORS 策略阻止 - Fetching wp_mail has been blocked by CORS policy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM