我正在调用API内置节点js,并将POST方法的主体作为JSON传递。JSON文件包含参数作为文件wallet_view.json
{"version":4.2,"auth_token":"0625d8042e2b2a04c5770f54a0c7a83d","page":1}
和节点js的索引文件:
const express = require('express');
const app = express();
const process = require('process');
const config = require('./config/config.js');
app.use(express.raw());
app.use(express.urlencoded({ extended: true }));
process.on('uncaughtException', function (error) {
console.log('Uncaught Exception: ' + error);
});
app.use((req, res, next) => {
console.log(req.originalUrl);
console.log(req.body);
const routes_handler = require('./routes/index.js')(app, express, req);
next();
});
app.listen(config.SERVER.PORT, () => {
console.log("Server running at Port " + config.SERVER.PORT);
});
我正在使用的命令如下:
ab -n 2 -c 1 -T 'application/x-www-form-urlencoded' -p ./wallet_view.json -A "username:password" -v 4 http://domainname.com/wallet/view
但是,现在在req.body
的控制台日志中,我得到的输出为
{ '"version":4.2,"auth_token":"0625d8042e2b2a04c5770f54a0c7a83d","page":1': '' }
这是错误的JSON格式。这样我无法获得req.body.auth_token
。谁能建议我在ab命令中应该做什么样的修改?
内容类型应为application/json
,而不是application/x-www-form-urlencoded
尝试这样,
ab -n 2 -c 1 -T 'application/json' -p ./wallet_view.json -A "username:password" -v 4 http://domainname.com/wallet/view