[英]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.