根据headers的不同:
fetch('books',{
method:'post',
body:'uname=lisi&pwd=123',
headers:{
'Content-Type':'application/x-www-form-urlencoded',
}
}).then(data => {
return data.text();
}).then(ret => {
//这里才是得到的最终数据
console.log(ret);
})
//后台接收参数为req.body.uname + '--' + req.body.pwd
//body是bodyParser提供支持
fetch('books',{
method:'post',
body:JSON.stringify({
uname:'张三',
age:12
})
headers:{
'Content-Type':'application/json',
}
}).then(data => {
return data.text();
}).then(ret => {
//这里才是得到的最终数据
console.log(ret);
})
//后台接收参数为req.body.uname + '--' + req.body.age