繁体   English   中英

Angular和Laravel授权标头CORS错误

[英]Angular and Laravel authorization header CORS error

我在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'标头

尝试使用laravel-cors插件。 我认为可以解决问题。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM