node之body-parser的使用


bodyparser 用來解析post的請求取代了 原生的 req.on 的方式 但是只能取到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模塊 必須同時應用

    同時用時效果如下:

 


免責聲明!

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



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