安裝
$ npm install body-parser
API
var bodyPaeser =require('body-parser')
bodyParse.raw(option)
將請求體內容作為Buffer來處理,並返回。支持gzip
deflate
壓縮。
bodyParser.text(option)
將請求提內容作為字符串來處理,並返回。支持gzip
deflate
壓縮。
bodyParser.urlencoded(option)
中間件只解析urlencoded
請求體,並返回,只支持UTF-8編號文本,支持gzip
deflate
壓縮。
const express=require('express'); const bodyParser=require('body-parser'); var server=express(); server.listen(8080); server.use(bodyParser.urlencoded({ extended: false, //擴展模式 limit: 2*1024*1024 //限制-2M })); server.use('/', function (req, res){ console.log(req.body); //POST //req.query GET //req.body POST });
https://www.cnblogs.com/gxp69/p/7235911.html nodejs body-parser 解析post數據