亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請求正文未從 Next.js 傳遞到 Node.js 服務器

請求正文未從 Next.js 傳遞到 Node.js 服務器

弒天下 2023-09-28 15:23:49
我想知道你是否能在這件事上幫助我。調用函數: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}`);


查看完整回答
反對 回復 2023-09-28
  • 1 回答
  • 0 關注
  • 96 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號