使用Cookie提取API

编程入门 行业动态 更新时间:2024-10-11 17:21:54
本文介绍了使用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

本文发布于:2023-11-24 19:44:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626568.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Cookie   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!