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