使用Postman发送数据

时间:2018-05-29 10:19:01

标签: node.js postman restify

我使用的是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() ;
});

我的邮差配置:

  • 内容类型 application / json
  • 在网址上发帖: http://127.0.0.1:8080/ping/value1 (为了测试查询参数)
  • Body as" Raw"内容: {"你好" :"世界" } (测试身体数据)

在POST查询之后,我可以获取查询参数,但是我无法获取正文数据:

{ param1: 'value1' }
undefined

1 个答案:

答案 0 :(得分:1)

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

curl -F "hello=world" localhost:5555/ping/goodbye

我在服务器stdout上得到了这个:

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

我不使用Postman所以我不知道它是否可能不适合你,但这适用于curl。

我的版本信息如下。

  

process.versions       {http_parser:'2.7.0',         节点:'8.2.1',         第8节:'5.8.283.41',         紫外线:'1.13.1',         zlib:'1.2.11',         ares:'1.10.1-DEV',         模块:'57',         openssl:'1.0.2l',         icu:​​'59 .1',         unicode:'9.0',         cldr:'31 .0.1',         tz:'2017b'}