Discord Webhook 访问控制允许来源

Discord Webhook Access-Control-Allow-Origin

我正在使用 Javascript 发送 Discord webhook 请求,但我不断收到以下错误: 在

访问 XMLHttpRequest

'WEBHOOK URL' from origin 'http://discordfastlist.ml' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

经过大量谷歌搜索,我确切地知道这是什么,尝试了我找到的所有解决方案,但似乎没有任何东西适用于 Discord webhooks。

我使用的代码:

var xhr = new XMLHttpRequest();
xhr.open("POST", "this is the webhook URL, I am not showing this in the code but it is there", true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
    'content': "test",
    'username':'Test Webhook',
}));

你需要能够事先与 discord 协商 CORS 策略,我认为这个人遇到了类似情况的同样麻烦。

您真正需要做的是执行飞行前响应并将正确的 cors-policy 附加到您的请求以及您的 javascript 请求