温馨提示×

debian postman怎样测试接口

小樊
38
2026-09-20 01:16:59
栏目: 智能运维

在 Debian 上用 Postman 测试接口,一般有两种方式:

  1. 桌面版 Postman(图形界面)
  2. 命令行版 Postman(Newman)

下面分别说明。


一、桌面版 Postman(推荐新手)

1. 安装 Postman(Debian)

Postman 官方提供 .deb 包:

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

或通过菜单启动。


2. 测试接口步骤

  1. 打开 Postman
  2. 点击 New → HTTP Request
  3. 填写:
    • Method:GET / POST / PUT / DELETE
    • URL:http://localhost:8080/api/test
  4. 如有参数:
    • Params(URL 参数)
    • Headers(如 AuthorizationContent-Type
    • Body(JSON / form-data)
  5. 点击 Send
  6. 查看:
    • Status(200 / 400 / 500)
    • Response Body
    • Response Time

二、命令行方式(Newman)

适合 服务器 / CI 测试

1. 安装 Node.js

sudo apt update
sudo apt install nodejs npm -y

2. 安装 Newman

sudo npm install -g newman

验证:

newman --version

3. 使用 Postman Collection 测试

  1. 在 Postman 中导出 Collection(.json
  2. 在 Debian 上运行:
newman run api_test.json

带环境变量:

newman run api_test.json -e env.json

三、常见测试示例

GET 请求

GET http://127.0.0.1:8080/user/1

POST JSON

{
  "username": "test",
  "password": "123456"
}

Header:

Content-Type: application/json

四、调试建议

  • 本地服务先 curl 测试:
curl http://localhost:8080/api/test
  • 检查防火墙 / 端口
  • 查看后端日志

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

  • 测试的是 本地接口还是远程
  • 接口类型(REST / WebSocket)
  • 是否需要在 无界面服务器 上跑

我可以给你更具体的示例。

0