javascript - 获取请求导致双重获取请求?
问题描述
我想使用 Fetch 做一个获取请求,然后重定向到应用程序页面,问题是重定向它自己封装另一个标头以任何方式进行干净的重定向,使用第一个请求而不是发出另一个请求?谢谢。
// First Request with authorization:
{
host: 'localhost:3000',
connection: 'keep-alive',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
authorization: 'Bearer undefined',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
'content-type': 'application/json',
}
// Second Request no authorization
{
host: 'localhost:3000',
connection: 'keep-alive',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
'sec-ch-ua-mobile': '?0',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
}
// Fetch Request
fetch('/app', {
credentials: "same-origin",
mode: "same-origin",
method: 'GET',
//redirect: 'follow',
headers: {
"Authorization": `Bearer ${JWTs}`,
"Content-Type": "application/json"
}
})
.then(response =>
// this is casing the redirection to happen and and to cause the other Get req making me losse the Auth header any other way to redirect ?
window.location = response.url
)
.catch((error) => {
console.error(error);
}).catch(err => {
if (err === "server") return
console.log(err)
})
}
})
解决方案
推荐阅读
- amazon-web-services - IAM 角色引用多个 EKS OIDC
- python - 如何从 Python 3.9.6 中的字符串中删除 BOM 字符?
- pyspark - 在 pyspark 中从另一个数据库加载表
- python - 无法检查字典中是否存在字符串[python]
- jenkins - Jenkins 通过 SSH 发布:如何在源文件中提供 windows 目录(例如:E:\Test\SFTP\In\Test.txt),在远程目录中提供远程 UNIX 目录
- swift - AR Kit 识别和播放多个视频
- python - Python:创建带有日期的字典时语法无效
- migration - 将多个课程从一台服务器迁移到另一台 Moodle 服务器
- elasticsearch - 建立graphDB elasticsearch连接器
- data-science - IsolationForest,转换数据