我有一個明確的應用程序和POST路線:Node.js:如何在POST中傳遞參數?
app.post('/test', function(req, res){
//res.send(req.body.title + req.body.body)
console.log(req.params);
console.log(req.body);
console.log(req.body.user);
console.log(req.body.feedback);
console.log("ok");
//return;
});
我嘗試做〜$ curl -X POST "http://xxxx.herokuapp.com/test?user=hello"
,我也得到:
TypeError: Cannot read property 'user' of undefined
at Router.<anonymous> (/app/app.js:40:22)
at done (/app/node_modules/express/lib/router/index.js:250:22)
at middleware (/app/node_modules/express/lib/router/index.js:244:9)
at param (/app/node_modules/express/lib/router/index.js:227:11)
at pass (/app/node_modules/express/lib/router/index.js:232:6)
at Router._dispatch (/app/node_modules/express/lib/router/index.js:255:4)
at Object.handle (/app/node_modules/express/lib/router/index.js:45:10)
at next (/app/node_modules/express/node_modules/connect/lib/http.js:198:15)
at Object.methodOverride [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:35:5)
at next (/app/node_modules/express/node_modules/connect/lib/http.js:198:15)~ $
難道不應該崗位工作?
感謝
它的工作,但現在我得到一個超時錯誤在服務器中。 – donald
這是因爲你的服務器沒有響應,只是記錄的東西。你不需要做'res.send('hi');'或者什麼? –