当我从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');
}
我在访问控制允许标头中添加了x-xsrf-Token,但我还是遇到了同样的问题。