码迷,mamicode.com
首页 > Web开发 > 详细

body-parser 是一个Http请求体解析中间件

时间:2017-06-20 18:12:34      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:api   中间   end   text   buffer   UI   安装   parser   创建   

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库。

body-parser 是一个Http请求体解析中间件

标签:api   中间   end   text   buffer   UI   安装   parser   创建   

原文地址:http://www.cnblogs.com/taiyanghua0522/p/7054781.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!