我正在尝试向discord api发出POST请求,但是它返回 {“ message”:“无法发送空消息”,“ code”:50006} 我还尝试过将FormData用于发布的内容和普通字符串。
function loadDoc()
{
let json = JSON.stringify({
"content": "test",
});
const http = new XMLHttpRequest()
http.open("POST", "https://discordapp.com/api/webhooks/MYWEBHOOK",true)
http.setRequestHeader("Content-Type","multipart/form-data")
http.send(json)
http.onload = () => console.log(http.responseText)
}
答案 0 :(得分:1)
也许采用获取方法:
let url = 'YOUR_URL';
let content = {YOUR_DATA};
let optionalParam = {
headers: {
"content-type":"application/json; charset=UTF-8"
},
body: content,
method: "POST"
};
fetch(URL, optionalParam)
.then(data => {return data.json()})
.then(res => {console.log(res)})
.catch(error => {console.log(error)})