利用 Nodejs & express4 製作 RESTful Web API
nodejs 使用app.use(express.bodyParser()); 出错
Express4後 bodyparser已经不和Express绑定在一起了
上例使用POST亦可選用 x-www-form-urlencoded
module.exports = function(app) {
app.get('/get', function (req, res){
res.send('Got a GET request');
console.log(req.query);
});
app.post('/post', function (req, res) {
//res.send('Got a POST request');
//res.headers req.body
res.send(req.headers.host);
});
app.get('*', notFound);
};
function notFound(req, res)
{
res.send('404', 'Page Not Found');
}

沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。