-- 创造无限可能

withCredentials:用户凭证,以及跨域的影响

2022-05-09 23:10:18
264 人浏览 0 人点赞
有用,点赞支持一下

withCredentials是XMLHttpRequest的 属性

默认值为false。在获取同域资源时设置 withCredentials 没有影响。

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

设置withCredentials,后端设置Access-Control-Allow-Origin: * 会报错

必须设置对应的请求域名

相关链接

https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest/withCredentials