withCredentials:默认情况下,跨源请求不提供凭据(cookie、HTTP认证及客户端SSL证明等)。通过将withCredentials属性设置为true,可以指定某个请求应该发送凭据。

  • 默认值为false。
  • true:在跨域请求时,会携带用户凭证
  • false:在跨域请求时,不会携带用户凭证;返回的 response 里也会忽略 cookie

当配置了 withCredentials = true时,必须在后端增加 response 头信息Access-Control-Allow-Origin,且必须指定域名,而不能指定为*!!!

这是最近遇到的问题,后端需要带cookie过去,而前端没有设置为true,所以导致cookie没有传过去,后来发现是没有设置为true

posted on 2020-06-15 17:34  Qionghuihe  阅读(4075)  评论(0编辑  收藏  举报