我在Angular中有一个拦截器,用于将角度发送给Laravel CORS
let headers = new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/x-www-form-urlencoded',
'Authorization': localStorage.getItem('token'),
});
let reqClone = req.clone({
headers: headers
});
在Laravel的中间件中
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Credentials', 'true')
->header('Access-Control-Allow-Methods', 'GET, HEAD, OPTIONS, POST, PUT')
->header('Access-Control-Max-Age', '3600')
->header('Access-Control-Allow-Headers', 'Origin, Accept, Content-Type, X-Requested-With');
我尝试访问
$request->header('authorization') // Laravel
但我收到与CORS相关的错误
来自来源“ http://localhost:4200”的信息已被CORS政策阻止:对预检请求的响应未通过访问控制检查:所请求的资源上没有“ Access-Control-Allow-Origin”标头>