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

相關文章
相關標籤/搜索