express - 从 ios 和 android 中的 react-native 应用程序获取响应中的不同 Set-Cookie 标头
问题描述
这很奇怪,但我只在 Android 设备上的 react-native 应用程序中看不到我的 express 服务器中的一些 set-cookie 标头!
我在我的 node.js 服务器上使用 express
const express = require('express');
const csrf = require('csurf');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const bodyParser = require('body-parser');
app.use(cookieParser());
app.use(session({
name: 'sid',
secret: CONSTANTS.SESSION_SECRET,
resave: false,
saveUninitialized: true
}));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
const csrfProtection = csrf();
app.use(csrfProtection);
app.get('/', (request, response, next) => {
response.cookie('csrftoken', request.csrfToken());
response.status(200).send(...);
});
我只是设置 csrftoken cookie 并发送一些响应;
在客户端上,我首先获得邮件页面:
fetch(URL_INDEX, {
method: 'GET',
headers: {
'User-Agent': USER_AGENT,
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
}
}).then((response) => {
//check response here <--------------------------------
processCookies(response);
return response;
})
我在调试器中看到的 fetch 答案:
在IOS中
Headers
map:Object
connection:"keep-alive"
content-length:"11716"
content-type:"text/html; charset=utf-8"
date:"Fri, 08 Feb 2019 10:58:25 GMT"
etag:"W/"2dc4-Ew7HRSMcOHECQlBtXIfAuuPw/Vs""
set-cookie:"csrftoken=bzKoDm5w-CdiLpGk0NWZ1TxaACRNJoRvVeng; Path=/, sid=s%3AGLvycaobuCL7xyIiNRBCXHSZU3SmHmAJ.vv9dzPurvicFvMb%2FkeB9Lshy6ZAQ0SvsMm8cR2ij9O8; Path=/; HttpOnly"
x-powered-by:"Express"
在安卓中
Headers
map: Object
connection:"keep-alive"
content-length:"11716"
content-type:"text/html; charset=utf-8"
date:"Fri, 08 Feb 2019 10:52:52 GMT"
etag:"W/"2dc4-Ew7HRSMcOHECQlBtXIfAuuPw/Vs""
set-cookie:"sid=s%3AOgeCB1Xsu8yA0SKiXF5Xgdc5pE-gSjfs.cDNHgzc41X1JmnUKmY6Hn3J2%2BrjxbXpBt7%2FhXwN6HbQ; Path=/; HttpOnly"
x-powered-by:"Express"
如您所见,csrftoken cookie 存在于 ios 上的响应中,但我们在 android 上看不到它。
有任何想法吗?
解决方案
推荐阅读
- python - 在不到一秒的时间内执行一个字谜检查器算法
- r - geom_bar 不显示平均值
- python - 如何将新行添加到现有 txt 文件
- json - 我可以阻止经过身份验证的用户查看我的整个 Firebase 数据库 JSON 文件吗?
- python-3.x - 将 Pandas 系列转换为表格
- amazon-web-services - 如果 AMI 或快照已加密以及使用 AWS 中的哪个密钥 AWS Managed CMK 或 Customer Manager CMK,我如何获取其详细信息
- vue.js - 当对象在 vue.js 中异步加载时,如何将 v-model 设置为对象属性?
- html - 文本是否应该成为可访问性的焦点?我特别在考虑键值对
- javascript - WebAssembly 应用程序如何将其本机 Window / OpenGL / Vulkan 调用映射到 DOM 中的画布元素?
- swift - 如何处理在firestore中包含具有空值字段的文档?