body-parser 是一個Http請求體解析中間件


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}))    

    extend

      ture->使用queryString庫(默認) false->使用qs庫。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM