node之body-parser的使用

bodyparser 用来解析post的请求取代了 原生的 req.on 的方式 可是只能取到ajax 和表单的数据 ,取不到上传的文件类型。ajax

let express = require('express');
let bodyParser = require('body-parser');
let app = express();
  1. //app.use(bodyParser.urlencoded({extended:false}));//解析 x-www-form-urlencoded

     

  2. app.use(bodyParser.text());//将全部的数据以文本格式字符串的返回 form表单中 text-plain

     

  3. app.use(bodyParser.raw());//解析二进制数据

     

  4. app.use(bodyParser.urlencoded({extended:false}));//解析 x-www-form-urlencoded
    app.use(bodyParser.json());//没法演示 解析json数据依赖于urlencoded模块 必须同时应用

    同时用时效果以下:express

相关文章
相关标签/搜索