如何获得 newman 的 JSON 响应
How to get the JSON response from newman
我试图 运行 在 postman 上 运行 的终点,我只是作为集合导出并 运行 在 JENKINS CI 上通过 newman 将其导出.
命令:
newman run <POSTMAN_COLLECTION>.json -r json,cli
我在当前目录中获取 response.json 文件,如下所示:
我无法在 json 文件中看到响应正文。
我在谷歌上搜索过,但没有成功。有没有办法得到这个 postmand_collection 的响应体?我怎样才能做到这一点?
我只想将响应正文作为 json 文件获取,我需要将其用作其他服务的请求。
您可以创建一个迷你项目并将 Newman 用作库,然后 运行 使用脚本将其使用。这样您就可以使用节点 fs
模块将响应写出到文件中。
const newman = require('newman'),
fs = require('fs');
newman.run({
collection: '<Your Collection>'
}).on('request', function (error, data) {
if (error) {
console.error(error);
}
else {
fs.writeFile(`response.json`, data.response.stream.toString(), function (error) {
if (error) {
console.error(error);
}
});
}
});
此脚本正在使用 Newman .on('request')
事件,它将提取该信息。如果你想要所有的响应主体,你可能需要稍微修改一下,并可能使用 appendFileSync
来捕获 all 来自集合中请求的响应。
我试图 运行 在 postman 上 运行 的终点,我只是作为集合导出并 运行 在 JENKINS CI 上通过 newman 将其导出.
命令:
newman run <POSTMAN_COLLECTION>.json -r json,cli
我在当前目录中获取 response.json 文件,如下所示:
我无法在 json 文件中看到响应正文。
我在谷歌上搜索过,但没有成功。有没有办法得到这个 postmand_collection 的响应体?我怎样才能做到这一点?
我只想将响应正文作为 json 文件获取,我需要将其用作其他服务的请求。
您可以创建一个迷你项目并将 Newman 用作库,然后 运行 使用脚本将其使用。这样您就可以使用节点 fs
模块将响应写出到文件中。
const newman = require('newman'),
fs = require('fs');
newman.run({
collection: '<Your Collection>'
}).on('request', function (error, data) {
if (error) {
console.error(error);
}
else {
fs.writeFile(`response.json`, data.response.stream.toString(), function (error) {
if (error) {
console.error(error);
}
});
}
});
此脚本正在使用 Newman .on('request')
事件,它将提取该信息。如果你想要所有的响应主体,你可能需要稍微修改一下,并可能使用 appendFileSync
来捕获 all 来自集合中请求的响应。