我想知道你是否能在这件事上帮助我。调用函数:function apiCreate(url, product) {console.log('Posting request API...' + JSON.stringify(product) );fetch(url, { dataType: 'json', method: 'post', body: product}).then(function(response) { console.log("we did it") return response.json();}).then(function(data) { console.log('Created Gist:', data.html_url);});接收的是:router.post('/create', (req, res) => { console.log('catalog product create Called.'); console.log('addProduct Called..'); console.log('req: '+ JSON.stringify(req.body));我可以到达终点,但主体不在“req”对象中。
1 回答

跃然一笑
TA贡献1826条经验 获得超6个赞
缺少标题,试试这个..
function apiCreate(url, product) {
try {
fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(product)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.log(error))
} catch (err) {
console.log(err)
}
}
接收...
router.post('/create', (req, res) => {
console.log('catalog product create Called.');
console.log('addProduct Called..');
console.log(`req ${body.req}`);
添加回答
举报
0/150
提交
取消