使用Cookie提取API [英] Fetch API with Cookie

查看:100
本文介绍了使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆