express.js get post body bug & solutions All In One
express.js get post body bug & solutions All In One
express.js get post body bug
fetch(`http://127.0.0.1:3000/api/post`, {
body: JSON.stringify({key: "value"}),
cache: "no-cache",
headers: {
"Content-Type": "application/json",
},
method: "POST",
// ❌, can not read post body data
mode: "no-cors",
})
.then(res => console.log(`res =`, res))
.catch(err => console.error(`error =`, err));
solutions
fetch(`http://127.0.0.1:3000/api/post`, {
body: JSON.stringify({key: "value"}),
cache: "no-cache",
headers: {
"Content-Type": "application/json",
},
method: "POST",
// ✅ can read post body data
// mode: "cors",
})
.then(res => console.log(`res =`, res))
.catch(err => console.error(`error =`, err));
fetch(`http://127.0.0.1:3000/api/post`, {
body: JSON.stringify({key: "value"}),
cache: "no-cache",
headers: {
"Content-Type": "application/json",
},
method: "POST",
// ✅ can read post body data
// mode: "no-cors",
})
.then(res => console.log(`res =`, res))
.catch(err => console.error(`error =`, err));
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14622164.html
未经授权禁止转载,违者必究!