body-parser 解析post數據


安裝

$ 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數據


免責聲明!

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



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