温馨提示×

linux postman如何测试接口

小樊
45
2026-10-12 11:45:26
栏目: 智能运维

在 Linux 下使用 Postman 测试接口,常见有三种方式:


一、使用 Postman 桌面版(图形界面)

1. 安装 Postman(Linux)

# Ubuntu / Debian
sudo snap install postman

# 或使用官方压缩包
wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz
tar -xvf postman.tar.gz
./Postman/Postman

2. 创建请求测试接口

  • 打开 Postman
  • 点击 New → HTTP Request
  • 选择方法:GET / POST / PUT / DELETE
  • 填写 URL,例如:
    http://localhost:8080/api/user
    
  • 设置:
    • Headers(如 Content-Type: application/json)
    • Body(raw → JSON)
  • 点击 Send
  • 查看返回状态码、响应体、耗时

二、使用 Postman CLI(Linux 无界面推荐)

1. 安装 Newman(Postman 命令行工具)

npm install -g newman

2. 导出 Postman Collection

  • Postman → Collection → Export
  • 得到 api_test.json

3. 命令行测试接口

newman run api_test.json

✅ 适合:

  • CI/CD
  • 服务器环境
  • 自动化测试

三、Linux 下不用 Postman(替代方案)

如果只想快速测试接口,也可以用 curl:

# GET
curl http://localhost:8080/api/user

# POST JSON
curl -X POST http://localhost:8080/api/user \
  -H "Content-Type: application/json" \
  -d '{"name":"test"}'

四、常见测试场景

  • ✅ 鉴权接口(Bearer Token)
  • ✅ 文件上传(form-data)
  • ✅ 接口自动化(Newman + Jenkins)
  • ✅ 环境变量(dev / test / prod)

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

  • 你用的是 Ubuntu / CentOS / 服务器无界面
  • 测试的是 REST / WebSocket / 文件上传

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

0 踩