How to force parse request body as plain text instead of json in Express?

后端 未结 8 2135
死守一世寂寞
死守一世寂寞 2021-01-03 17:49

I am using nodejs + Express (v3) like this:

app.use(express.bodyParser());
app.route(\'/some/route\', function(req, res) {
  var text = req.body; // I expect         


        
8条回答
  •  既然无缘
    2021-01-03 18:23

    In express 4.x you can use the text parser from bodyParser https://www.npmjs.org/package/body-parser

    just add in app.js

    app.use(bodyParser.text());
    

    Also in the desired route

    router.all('/',function(req,res){
        console.log(req.body);
    
    })
    

提交回复
热议问题