加上credentials: ‘include’ 报错

fetch 中加上 credentials: 'include' 反而会报错 跨域问题。怎么解决

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'.

回答

当 Access-Control-Allow-Origin 的值为 '*' 的时候跨域请求不允许携带认证
那么只能在服务端修改 Access-Control-Allow-Origin 的值,改成你指定的允许跨域访问的域的值
比如 Access-Control-Allow-Origin: http://192.168.1.1

以上是加上credentials: ‘include’ 报错的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>