1.這個模塊提供以下解析器
(1) JSON body parser (2) Raw body parser (3)Text body parser (4)URL-encoded form body parser
2.如何安裝
npm install body-parser
3.API
var bodyParser = require('body-parser');
可以通過body-parser對象創建中間件,當接受到客戶端請求時所有的中間件都會給req.body添加屬性,請求內容為空時,解析為空或者錯誤。
(1)bodyParser.json(options)
處理json數據
app.use(bodyParser.json());
(2)bodyParser.raw(options)
處理Buffer數據流
(3)bodyParser.text(options)
處理文本數據
(4)bodyParser.urlencoded(options)
處理UTF-8的編碼的數據
app.use(bodyParser.urlencoded({extented:false}))