search

Home  >  Q&A  >  body text

node.js - fetch submits post requests across domains, but the background node cannot accept ctx.request.body?

用fetch提交跨域的post请求,但是后台node服务根本找不到提交的数据,没有body的属性
请求代码如下:

  let url='http://127.0.0.1:8080/manager/user/add';
 fetch(url , {  
  method: 'POST',  
 headers: {},
    credentials: 'credentials',
    cache: 'default',
   body: `projectName=dddddd ` 
  // body: insertData,  
}).then((response) => {  
  if (response.ok) {  
      return response.json();  
  }  
}).then((json) => {  
  let userList=JSON.stringify(json);
   dispatch({ type:ADD_USER, userList: userList });  
}).catch((error) => {  
  console.error(error);  
}); 
    }
   后台打印如下: 

Could you please take a look! !

给我你的怀抱给我你的怀抱2752 days ago892

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-05-16 13:40:39

    Header content needs to be added, taking json as an example:
    headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:40:39

    Node needs to introduce the body-parser middleware module to obtain ajax submission.

    reply
    0
  • Cancelreply