温馨提示×

debian如何用postman测试

小樊
34
2026-09-26 00:15:08
栏目: 智能运维

在 Debian 上用 Postman 测试接口,一般有 两种方式:
1️⃣ 安装 Postman 桌面版(推荐)
2️⃣ 使用 命令行版 Postman(Newman)

下面分别说明。


一、在 Debian 安装并使用 Postman 桌面版

方法 1:通过 Snap 安装(最简单)

sudo apt update
sudo apt install snapd -y
sudo snap install postman

启动:

postman

或

snap run postman

方法 2:手动下载 AppImage(适合无 snap 环境)

wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz
tar -xvzf postman.tar.gz
cd Postman
./Postman

可创建桌面快捷方式:

sudo ln -s $(pwd)/Postman /usr/local/bin/postman

Postman 基本测试步骤

  1. 打开 Postman
  2. 新建 Request
  3. 选择方法:GET / POST / PUT / DELETE
  4. 输入 URL(如 http://localhost:8080/api/test)
  5. 设置:
    • Headers(如 Content-Type: application/json)
    • Body(JSON / form-data)
  6. 点击 Send
  7. 查看 Response(状态码、返回数据)

二、使用 Newman(命令行 Postman)

适合 服务器 / CI 环境

安装 Node.js

sudo apt install nodejs npm -y

安装 Newman

sudo npm install -g newman

导出 Postman Collection

  • Postman → Collection → Export → test.json

运行测试

newman run test.json

带环境变量:

newman run test.json -e env.json

三、Debian 上测试本地服务示例

假设本地有服务:

curl http://localhost:3000/api/hello

Postman 中:

  • Method: GET
  • URL: http://localhost:3000/api/hello

四、常见问题

❌ 无法启动(缺少依赖)

sudo apt install libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 -y

❌ Debian 无图形界面

✅ 用 Newman(命令行)


如果你愿意,可以告诉我:

  • Debian 是否 有桌面环境
  • 测试的是 HTTP / HTTPS / WebSocket
  • 是否是 本地服务 / 远程接口

我可以直接给你 具体操作示例。

0 踩