在 Linux 下使用 Postman 进行批量请求,常见有几种方式,取决于你是「GUI Postman」还是「命令行(Newman / Postman CLI)」。下面按使用场景说明。
✅ 适合:接口回归、参数遍历
例如请求:
GET /user/{{id}}
数据文件 data.json:
[
{ "id": 1 },
{ "id": 2 },
{ "id": 3 }
]
Runner 中选择该文件即可批量请求。
npm install -g newman
Postman → Collection → Export → collection.json
newman run collection.json
newman run collection.json -d data.json
newman run collection.json -n 10
newman run api_test.json \
-d users.csv \
-e env.json \
-r cli,html \
--delay-request 500
✅ 适合:CI / 定时任务 / 服务器
postman collection run collection.json
(功能类似 Newman,逐步替代)
如果只是简单批量:
for i in 1 2 3 4 5; do
curl -X GET "http://api.test/user/$i"
done
或并发:
seq 1 100 | xargs -P 10 -I {} curl http://api.test/user/{}
crontab -e
0 2 * * * newman run /opt/test/collection.json -d /opt/test/data.json
| 场景 | 推荐方式 |
|---|---|
| 手动测试 | Postman GUI Runner |
| 参数遍历 | Runner + 数据文件 |
| 服务器/CI | Newman |
| 高性能并发 | Shell + curl |
| 定时任务 | Newman + crontab |
如果你能告诉我:
我可以给你一个具体可直接用的示例。