我想使用 Fetch 执行一个 get 请求,然后重定向到应用程序页面 问题是重定向它自己封装了另一个标头,以任何方式进行干净的重定向,使用第一个请求而不是另一个请求?谢谢。
// 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)
})
}
})