在 CentOS 下使用 Postman,常见有两种方式:
下面分别说明。
cd /tmp
wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz
sudo tar -xzf postman.tar.gz -C /opt
sudo ln -s /opt/Postman/Postman /usr/bin/postman
postman
或直接在桌面环境中搜索 Postman
⚠️ 注意
- CentOS 必须 有桌面环境(GNOME / KDE)
- 如果是服务器版(无 GUI),请使用 Newman
如果你是在 CentOS 服务器 上,只能使用命令行方式。
curl -sL https://rpm.nodesource.com/setup_18.x | sudo bash -
sudo yum install -y nodejs
验证:
node -v
npm -v
sudo npm install -g newman
验证:
newman --version
在 Windows / Mac 的 Postman 中:
运行:
newman run example.postman_collection.json
带环境变量:
newman run test.json -e env.json
生成 HTML 报告:
npm install -g newman-reporter-htmlextra
newman run test.json -r htmlextra
newman run api_test.json \
--env-var "host=192.168.1.100" \
--env-var "token=abc123"
newman run api_test.json || exit 1
| 使用场景 | 推荐方式 |
|---|---|
| CentOS 有桌面 | Postman 桌面版 |
| CentOS 服务器(无 GUI) | Newman |
| 自动化测试 | Newman |
| 接口调试 | Postman |
如果你愿意,可以告诉我:
我可以给你更精确的命令。