如何在node.js中获取body参数

那么我刚开始在node.js中编程 我被困在一个地方。

我得到我的请求参数

response: --------------------------e2a4456320b2131c sent --------------------------e2a4456320b2131c Content-Disposition: form-data; name="is_test" true --------------------------e2a4456320b2131c Content-Disposition: form-data; name="success" true --------------------------e2a4456320b2131c-- 

我怎样才能获取所有这些参数:

is_testsuccess

这是我的代码:

  var express = require('express'), bodyParser = require('body-parser'); var app = express(); app.use(bodyParser.json()); exports.helloWorld = functions.https.onRequest((request, response) => { var body = ""; request.on('data', function (data) { body += data; }); request.on('end', function() { console.log('response: ' + body); }); }); 

您需要configuration路由器来处理请求。 看一下expression文档的hello world示例http://expressjs.com/en/starter/hello-world.html

而且,如果你正在发送数据,你正在寻找一个http post方法。 例:

 const bodyParser = require('body-parser'); const express = require('express'); const app = express(); app.use(bodyParser.json()); app.post('/', function (req, res) { const body = req.body; /*Body logic here*/ res.status(200).end(); }) app.listen(3000, function () { console.log('Example app listening on port 3000!'); })