无法使用 Postman 发送数据并通过 resify 获取请求正文

Can't get request body with resify using Postman to send data

我正在使用 Restify 服务器(节点版本是 v9.11.1,restify 版本是 6.4.0)。

这是我的服务器配置:

server.use(restify.plugins.queryParser({  mapParams: true }))
server.use(restify.plugins.bodyParser({  mapParams: true }));
server.pre(restify.plugins.pre.userAgentConnection());
server.use(restify.plugins.acceptParser(server.acceptable));

server.pre(cors.preflight);
server.use(cors.actual);

现在,我想使用 Postman 使用代码示例进行测试。我想测试查询参数和正文参数:

server.post('/ping/:param1', (req, res, next ) => {
console.log(req.params);
console.log(req.body);
res.send(200, { "ping" :true} );
return next() ;
});

我的 Postman 配置:

经过POST查询后,我可以获取查询参数,但无法获取正文数据:

{ param1: 'value1' }
undefined

我刚刚使用上面列出的服务器设置创建了一个简单的 restify 服务器,除了省略了 cors 的东西。然后我使用 curl:

访问服务器
curl -F "hello=world" localhost:5555/ping/goodbye

我在服务器标准输出上得到了这个:

{ param1: 'goodbye', hello: 'world' }
{ hello: 'world' }

我不使用 Postman,所以我无法判断它是否适合您,但这与 curl 配合使用效果很好。

我的版本信息如下

process.versions { http_parser: '2.7.0', node: '8.2.1', v8: '5.8.283.41', uv: '1.13.1', zlib: '1.2.11', ares: '1.10.1-DEV', modules: '57', openssl: '1.0.2l', icu: '59.1', unicode: '9.0', cldr: '31.0.1', tz: '2017b' }