【发布时间】:2019-04-23 00:13:18
【问题描述】:
我正在尝试向 json blob api 发出 POST 请求(这是一个用于存储我的 JSON 文件的简单 api)。我收到 405 错误...
我不知道为什么我不能做 POST 请求,当 GOT 请求工作正常时..
有人可以帮帮我吗? https://jsonblob.com/api
const api = "https://jsonblob.com/api/jsonBlob/c30c8afa-6557-11e9-acbe-
61e96b39ce8b"
//it doesn't work
fetch(api, {
method: 'POST',
body: JSON.stringify({
name: 'dean',
login: 'dean',
})
})
.then(response => {
if (response.ok) {
return response.json()
}
throw new Error('Request failed!')
})
.then(jsonResponse => {
console.log(jsonResponse)
})
.catch(error => {
console.log('Request failure: ', error);
});
// get request works fine
fetch(api).then((response) => {
if (response.ok) {
return response.json();
console.log(response)
}
throw new Error('Request failed! ');
})
.then((Jsondata) => {
console.log(Jsondata)
})
.catch(error => {
console.log(error.message)
});
【问题讨论】:
-
哦,等等……您根本没有阅读 api 文档 - 为什么您的 POST 中有一个 blobid?
标签: javascript api post request fetch