Access to fetch at 'http://localhost:3001/trigger-preflight'from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field content-type isnot allowed by Access-Control-Allow-Headers in preflight response.
复制代码
Access to fetch at 'http://localhost:3001/trigger-preflight' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.复制代码
不过如果你在 a 域送出了 b 域的请求,且 b 域回传了 cookie 的信息,那么在 a 域会以 b 域的形式储存一份cookie,如果没有设定
withCredentials
或是
credentials: ‘include’
的话,就算服务器回传了
Set-Cookie
,一样不会被写入。如下图:
服务器回传Set-Cookie
没有写入浏览器中
在一般情况下如果再使用 b 域的 API,cookie 是不会自动被送出去的。这个情况下,你必须在
XHR
设定
withCredentials
或是
fetch
的选项中设置
{ credentials: 'include' }
,因为这也是一个跨域请求,所以也必须按照 CORS 条件加入
Access-Control-Allow-Origin
Access to fetch at 'http://localhost:3001/cookie'from origin 'http://localhost:3000' has been blocked by CORS policy: 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'.
复制代码