admin管理员组文章数量:1794759
Response to preflight request doesn‘t pass access control check: The value of the ‘Access
错误:Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
处理方式:
1、转自:www.jianshu/p/ea485e5665b3
Access-Control-Allow-Credentials
追风骚年关注
12019.03.31 15:17:07字数 369阅读 34,601
前后端分离的项目中肯定会碰到跨域的问题,究其原因还是为了安全。我在一个前端工程调试过程中发现,即使我后端已经允许了跨域,但是前端依然报一个跨域错误。
Access to XMLHttpRequest at 'localhost/api/admin/authorizations' from origin 'localhost:9528' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.尝试了很多网上的方法也都没有弄清原因在哪里。索性就仔细研究一下 Access-Control-Allow-Credentials 这个头的作用,果然药到病除。这个是服务端下发到客户端的 response 中头部字段,意义是允许客户端携带验证信,例如 cookie 之类的。这样客户端在发起跨域请求的时候,不就可以携带允许的头,还可以携带验证信的头,又由于客户端是请求框架是 axios,并且手残的设置了 withCredentials: true,意思是客户端想要携带验证信头,但是我的服务端设置是 'supportsCredentials' => false, ,表示不允许携带信头,好了,错误找到了。
我们的客户端和服务端交互的时候使用的是 token,通过 Authorization头发送到服务端,并没有使用到 cookie,所以客户端没有必要设置 withCredentials: true,一顿操作猛如虎🤣🤣。
2、转自:wwwblogs/chen55555/p/11584785.html
跨域问题The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by twithCredentials 属性
上面说到,CORS请求默认不发送Cookie和HTTP认证信。如果要把Cookie发到服务器,一方面要服务器同意,指定Access-Control-Allow-Credentials字段。
出现这个报错信很可能是你在前端设置了withCredentials = true;你可以去掉这个设置也可以参考下面两个博客
juejin.im/post/5c2490ba6fb9a049ff4e2eca
blog.csdn/nlldwbiqjs/article/details/82887180
ningyu1.github.io/site/post/92-cors-ajax/
本文标签: requestpassresponsepreflightCheck
版权声明:本文标题:Response to preflight request doesn‘t pass access control check: The value of the ‘Access 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686964240a123016.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论