【发布时间】:2022-01-13 13:31:59
【问题描述】:
我正在尝试向我的 API 发送一个网络推送订阅对象,该对象由“端点”和“密钥”组成。
我似乎遇到的问题是,当该对象到达我的 API 时,它具有“键”值但“端点”值为空。然而,当我调试它时,我可以确认端点值已定义。
这是我正在使用的 JS 代码:
async function Subscribe() {
let sw = await navigator.serviceWorker.ready;
let push = await sw.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey:
'ApplicationServerKeyHere'
});
console.log(JSON.stringify(push)); //Store this in DB
fetch("https://localhost:44325/Subscribe", {
method: "POST",
//credentials: "same-origin", // include, *same-origin, omit
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(push)
});
}
在发送 Fetch POST 之前填充端点:
然后在到达API时清空:
【问题讨论】:
标签: javascript web-push