![](/img/trans.png)
[英]How to send fetch post request to an API key based authorized endpoint?
[英]Send cookie and API Key on the fetch request
我正在向 API 发送 GET 请求。 浏览器必须在获取请求上发送一个 cookie 和一个 API 密钥。
我面临的问题如下:
fetch(urlToRequest, {
method: "GET",
mode: "cors",
credentials: "include"
})
.then((response) => {
console.log(response);
})
.catch ((error) => {
console.log(error)
});
fetch(urlToRequest, {
method: "GET",
mode: "cors",
credentials: "include",
headers: {"api-key": apiKey}
})
.then((response) => {
console.log(response);
})
.catch ((error) => {
console.log(error)
});
这种行为正常吗? 浏览器不应该发送 cookie 和 api 密钥吗?
这是 Chrome 的问题,在某些情况下 Chrome 调试器不显示 cookie。 我认为cookie已发送。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.