温馨提示×

debian如何用postman测

小樊
44
2026-09-23 00:51:08
栏目: 智能运维

在 Debian 上用 Postman 测试接口,一般有两种方式:图形界面 Postman 和 命令行 Newman(Postman 的 CLI)。下面按常见使用场景说明。


一、在 Debian 上安装 Postman(图形界面)

方式 1:通过官方 tar 包(推荐)

# 下载
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

如果是 无桌面环境(服务器),无法使用图形界面,请看下面 Newman 方案。


方式 2:通过 Snap(不推荐在纯服务器用)

sudo apt install snapd
sudo snap install postman

二、用 Postman 测试接口(基本步骤)

  1. 打开 Postman
  2. 新建 Request
  3. 设置:
    • Method:GET / POST / PUT / DELETE
    • URL:http://localhost:8080/api/test
  4. 如果是 POST:
    • Body → raw → JSON
    {
      "username": "test",
      "password": "123456"
    }
    
  5. 点击 Send
  6. 查看:
    • Status(200 / 400 / 500)
    • Response Body
    • Headers

三、Debian 无界面方案:Newman(Postman CLI)

1. 安装 Node.js

sudo apt update
sudo apt install nodejs npm

2. 安装 Newman

sudo npm install -g newman

3. 导出 Postman Collection

在 Postman 中:

  • 选择 Collection
  • 点击 Export
  • 保存为 test.postman_collection.json

4. 运行测试

newman run test.postman_collection.json

带环境变量:

newman run test.postman_collection.json \
  -e env.postman_environment.json

四、常见问题

1. Debian 服务器没桌面怎么办?

✅ 用 Newman
✅ 或在本地 Windows / macOS 跑 Postman,连接 Debian 服务

2. 测试本地服务连不上?

检查:

curl http://localhost:8080/api/test

确认:

  • 服务已启动
  • 防火墙未拦截
  • 监听地址不是 127.0.0.1 以外被限制

3. HTTPS 自签名证书报错?

Postman 中:

  • Settings → General → SSL certificate verification → OFF

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

  • 你是 桌面 Debian 还是服务器
  • 测的是 HTTP / HTTPS / 本地服务 / 鉴权接口

我可以直接给你一套可运行的示例。

0 踩