当我从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仍然会遇到同样的问题
阅读错误消息:
Access-Control-Allow-Headers不允许请求头字段ip
它说ip
是不允许的。
看看你的代码:
'Origin, Content-Type, X-Auth-Token, Authorization, X-Requested-With, x-xsrf-token'
你的代码没有提到ip
。
将ip
添加到允许的标头列表中。