我正在使用Node.js創建一個API POST並進行表達。我只是想用html格式發佈一些數據:HTML表單請求正文空 - NodeJs
<form id="myform" action="http://localhost:4000/add" method="post" enctype="application/json">
<input type="text" name="name" id="name" />
<input type="submit" id="submit" />
</form>
服務器只會收到POST請求並將主體顯示到console.log中。
router.post('/add', function (req, res){
console.log("request: "+JSON.stringify(req.body));
})
什麼是在控制檯接收是: 要求:{}
嘗試後到郵差使用相同的API - 生,JSON(應用/ JSON),東西很好地工作。
有人能告訴我我在做什麼錯?
問題是以前問:https://stackoverflow.com/questions/4295782/how-do-you-extract-post-data-in-node-js –