我正在尝试使用以下命令发布一个JSON对象
获取
..。
据我所知,我需要将一个字符串对象附加到请求的正文中,例如:
fetch("/echo/json/",
{
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: "POST",
body: JSON.stringify({a: 1, b: 2})
})
.then(function(res){ console.log(res) })
.catch(function(res){ console.log(res) })
当使用
jsfiddle的json回声
我希望看到我发送的对象(
)返回,但这并没有发生- chrome devtools甚至没有将JSON显示为请求的一部分,这意味着它没有被发送。
发布于 2017-02-28 02:20:18
我觉得你的问题是
can进程
仅限请求。
但是正确的方法是传递正确的json请求
作为一个主体:
fetch('https://httpbin.org/post', {
method: 'post',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify({a: 7, str: 'Some string: &=&'})
}).then(res => res.json())
.then(res => console.log(res));
https://stackoverflow.com/questions/29775797
复制相似问题