javascript - 在 React Native 中没有使用 fetch() 获取 Set-Cookie 标头
问题描述
我是使用带有 React Native 的 Fetch API 的新手,我正在将它用于我的一个项目。我需要fetch()方法来获取set-cookie 标头并获取PHPSESSID值。这是我拥有的代码。
fetch("https://fs.auroville.org.in/", {
credentials: 'include',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
}
})
.then(request => {
console.log(request.headers)
//console.log(get_set_cookies(request.headers))
})
.catch((error) => {
console.log("Error")
console.error(error)
});
它似乎可以与我的代码一起使用,但由于某种原因,set-cookie 标头似乎没有出现。我知道它仅在您第一次打开它时才会显示在 Google Chrome 检查选项卡的网络选项卡中,但之后不会。
我想知道是否有人可以提供帮助,因为我做了很多研究,但我似乎找不到可靠的解决方案,即使我第一次调用该函数时,“Set-Cookie”标头也没有显示但每个其他标题都会这样做。
这是 get_set_cookies() 函数的代码
const get_set_cookies = function(headers) {
const set_cookies = []
for (const [name, value] of headers) {
set_cookies.push(value)
}
return set_cookies
}
解决方案
推荐阅读
- spring-cloud-gateway - Spring云网关——FeignBlockingLoadBalancerClient
- sql-server - System.Data.SqlClient.SqlException:'')' 附近的语法不正确。' 有什么建议吗?
- javascript - 添加属性后 Tailwind CSS 无法正确构建
- php - 从 PHP 7.0 升级到 PHP 8.0
- mysql - Azure 数据工厂 V2 更新 SQL 记录
- python - Selenium python 服务器身份验证
- javascript - JavaScript 表单上传文件
- python - django.views 的导入问题
- python - kivy 中的参考模板(?)小部件
- arrays - Powershell ConvertFrom-Json:根据属性名称选择嵌套数组的值