2012-02-17 8 views

答えて

44

答えが見つかりました。付属のプラグインの1つを有効化する必要があります()。 settings(具体的にはBodyParserセクションを参照)に応じて、req.params(デフォルト)またはreq.bodymapParams: false)のいずれかにデータが見つかります。

例:

server.use(restify.bodyParser({ mapParams: false })); // mapped in req.body 

または:

server.use(restify.bodyParser()); // mapped in req.params 
5

は非常に簡単です:

server.use(restify.bodyParser({ mapParams: false })); 

あなたはこのコードが印刷されますrestify

1

でbodyParserを有効にする必要があります要求団体コンソールへ:

restify 5.0.0+については
var restify = require('restify'); 
var server = restify.createServer(); 

// This line MUST appear before any route declaration such as the one below 
server.use(restify.bodyParser()); 

server.post('/customer/:id', function (req, resp, next) { 
    console.log("The request body is " + req.body); 
    response.send("post received for customer " + req.params.id + ". Thanks!"); 
    return next(); 
}); 
3

、使用:

server.use(restify.plugins.bodyParser()); 

https://github.com/restify/node-restify/issues/1394#issuecomment-312728341

古いバージョンを使用してください:

server.use(restify.bodyParser()); 

bodyParserミドルウェアに要求を使用するようにrestifyを語った後、要求に応じてボディが利用可能になりますオブジェクトボディプロパティ:

server.post('/article', (req, res, next) => { 
    console.log(req.body) 
    next() 
}) 
関連する問題