本文介绍了使用Cookie提取API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试新的Fetch API,但Cookie遇到了问题。具体来说,成功登录后,以后的请求中会有一个Cookie标头,但Fetch似乎忽略了这些标头,而我使用Fetch进行的所有请求都是未经授权的。
I am trying out the new Fetch API but is having trouble with Cookies. Specifically, after a successful login, there is a Cookie header in future requests, but Fetch seems to ignore that headers, and all my requests made with Fetch is unauthorized.
是
我使用Webpack构建应用程序。我还在React Native中使用了Fetch,它没有相同的问题。
I build my app with Webpack. I also use Fetch in React Native, which does not have the same issue.
推荐答案默认情况下,Fetch不使用cookie。要启用Cookie,请执行以下操作:
Fetch does not use cookie by default. To enable cookie, do this:
fetch(url, { credentials: "same-origin" }).then(...).catch(...);更多推荐
使用Cookie提取API
发布评论