【发布时间】:2019-02-17 16:43:00
【问题描述】:
如何用formdata创建post服务?
我通过 Axios 发送了表单数据。 但是,node-express 服务器上的“req.body.title”的值为空。 所以现在我以以下格式发送 fetch 。 但是我需要将文件上传到服务器,所以我想使用formData发送它。
let bodys = 'title=a1&contents=b'
fetch("http://localhost:5000/test", {
method : 'post',
headers : {
'Content-type' : 'application/x-www-form-urlencoded; charset=UTF-8'
},
body: bodys
})
.then(function(response){
console.log('Request Succeded ', response);
})
.catch(function (error){
console.log('Failed ', error)
})
我使用 append 和 new FormData() 编写了新数据, 我检查了 FormData 是否包含 React 上的值。 但是node-express服务器没有进入body。
请告诉我该怎么做...
【问题讨论】:
标签: node.js reactjs post fetch axios