Accessing raw POST data in Express

后端 未结 2 924
执念已碎
执念已碎 2020-12-11 09:52

I\'m trying to write a stupidly simple Hello World program in Express that outputs some basic data about the current HTTP request.

For POST requests, I\'d like to se

2条回答
  •  遥遥无期
    2020-12-11 10:50

    1. If you required parsing of url-encoded (non-multipart) form data, as well as JSON, try adding:

      var bodyParser = require('body-parser');
      
      
      // Put these statements before you define any routes.
      app.use(bodyParser.urlencoded({ extended: true}));
      app.use(bodyParser.json());
      
    2. To handle multi-part form data, the bodyParser.urlencoded() body parser will not work. you can refer this for alternatives of extracting data from form-data

提交回复
热议问题