bodyParser 支持此类参数解析. 注意: 在提交之前需要指定http 请求头为 content-type=application/json 代码如下: var express = require(‘express‘); var bodyParser = require(‘body-parser‘); var multipart = require(‘connect-multiparty‘); var multipartMiddleware = multipart(); //var morgan = require(‘morgan‘); var app = express(); var server = require(‘http‘).createServer(app); app.use(bodyParser.json({limit: ‘1mb‘})); //这里指定参数使用 json 格式 app.use(bodyParser.urlencoded({ extended: true })); app.post(‘/json‘, function (req, res) { console.log(req.body); res.send(req.body); }); var PORT = process.env.PORT || 8002; server.listen(PORT);
时间: 2024-12-29 11:24:25