温馨提示×

ubuntu postman怎么测试接口

小樊
47
2026-09-09 23:32:04
栏目: 智能运维

Ubuntu 上使用 Postman 测试接口,一般步骤如下:


一、安装 Postman(Ubuntu)

方式 1:通过 Snap 安装(推荐)

sudo snap install postman

安装完成后,在应用菜单搜索 Postman 即可打开。

方式 2:官网下载

  1. 打开 https://www.postman.com/downloads/
  2. 下载 Linux 版本(.tar.gz
  3. 解压并运行:
tar -xzf Postman-linux-x64-*.tar.gz
./Postman/Postman

二、使用 Postman 测试接口

1️⃣ 新建请求

  • 打开 Postman
  • 点击 New → HTTP Request
  • 输入接口地址,例如:
http://localhost:8080/api/user

2️⃣ 选择请求方法

常见方法:

  • GET:查询数据
  • POST:新增数据
  • PUT:更新数据
  • DELETE:删除数据

3️⃣ 设置请求参数

GET 请求

  • Params 中添加:
key: id
value: 1

POST / PUT 请求

  • 切换到 Body
  • 选择:
    • raw → JSON
    • 示例:
{
  "username": "test",
  "password": "123456"
}

4️⃣ 设置请求头(Headers)

例如:

Content-Type: application/json
Authorization: Bearer token值

5️⃣ 发送请求

  • 点击 Send
  • 查看:
    • Status(200 / 400 / 500)
    • Response Body
    • Response Time

三、测试本地接口示例

假设 Ubuntu 本地有接口:

GET http://127.0.0.1:3000/api/hello

Postman 中:

  • Method: GET
  • URL: http://127.0.0.1:3000/api/hello
  • 点击 Send

返回:

{
  "message": "Hello from Ubuntu"
}

四、常见问题

❓ 无法连接 localhost

  • 确认服务已启动
  • 防火墙未拦截端口
  • 如果是 Docker 服务,用:
http://host.docker.internal

❓ 接口返回 403 / 401

  • 检查 Token
  • 检查请求头是否正确

如果你有 具体接口示例(如 Spring Boot / Flask / Node.js),我可以帮你写 Postman 测试配置

0