我试图向不和谐的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)
}发布于 2020-02-12 09:30:51
也许可以对fetch采取如下方法:
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)})https://stackoverflow.com/questions/60184373
复制相似问题