在 Linux 下用 Postman 调试接口,常见有 两种方式:
1️⃣ 使用 Postman 桌面版(GUI)
2️⃣ 使用 Postman CLI(newman) 或 curl 替代
下面按使用场景给你讲清楚。
Postman 官方提供 .tar.gz 包:
# 下载
wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz
# 解压
tar -xzf postman.tar.gz -C /opt
# 创建软链接
ln -s /opt/Postman/Postman /usr/local/bin/postman
启动:
postman
如果是 Ubuntu / Debian,也可以直接搜 Postman(Snap):
sudo snap install postman
http://localhost:8080/api/user)✅ 查看请求详情
✅ 环境变量
base_url✅ Pre-request Script
pm.environment.set("token", "abc123");
✅ Tests 断言
pm.test("状态码是200", function () {
pm.response.to.have.status(200);
});
curl -X GET "http://localhost:8080/api/user" \
-H "Authorization: Bearer token"
POST JSON:
curl -X POST "http://localhost:8080/api/login" \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"123456"}'
适合 自动化测试
# 安装
npm install -g newman
# 运行 Postman 导出的 collection
newman run api_test.postman_collection.json
sudo apt install libgconf-2-4
或检查是否是 64 位系统
0.0.0.0sudo ufw status
Postman → Settings → SSL certificate verification → OFF(仅测试环境)
| 方式 | 适合场景 |
|---|---|
| Postman GUI | 本地开发、可视化调试 |
| curl | 服务器、快速验证 |
| Newman | 自动化接口测试 |
如果你愿意,可以告诉我:
我可以直接给你 具体操作示例。