温馨提示×

ubuntu下postman怎调试

小樊
41
2026-10-01 02:41:01
栏目: 智能运维

在 Ubuntu 下使用 Postman 调试接口,一般流程如下(从安装到常用调试技巧):


一、安装 Postman(Ubuntu)

方式 1:官方 AppImage(推荐)

  1. 到官网下载 Linux 版
    https://www.postman.com/downloads/
  2. 赋予执行权限并运行:
chmod +x Postman-linux-x64-*.AppImage
./Postman-linux-x64-*.AppImage

方式 2:Snap 安装

sudo snap install postman

二、基本调试流程

1. 创建请求

  • 打开 Postman
  • 点击 New → HTTP Request
  • 选择方法:GET / POST / PUT / DELETE
  • 填写 URL(如 http://localhost:8080/api/test)

2. 设置请求参数

  • Params:URL 查询参数
  • Headers:如
    Content-Type: application/json
    Authorization: Bearer xxx
    
  • Body:
    • raw → JSON
    {
      "username": "admin",
      "password": "123456"
    }
    

3. 发送请求

点击 Send,查看:

  • Status(200 / 400 / 500)
  • Response Body
  • Response Headers
  • Time / Size

三、常用调试技巧

✅ 1. 查看完整请求(Debug)

  • 点击 Send 下方 ▼
  • 选择 Show Raw Request
  • 或开启 Postman Console(快捷键 Ctrl + Alt + C)

✅ 2. 使用 Environment(环境变量)

  • 新建 Environment
base_url = http://localhost:8080
  • 请求中使用:
{{base_url}}/api/test

✅ 3. 本地服务调试

如果是本地后端:

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

确认服务在跑,再在 Postman 测试

✅ 4. 处理跨域 / Cookie

  • 关闭 Chrome 安全模式不必要
  • 后端需允许 CORS
  • 登录态可用 Cookies 管理

✅ 5. 脚本调试(Tests / Pre-request)

console.log(pm.response.json());
pm.test("状态码为200", () => {
  pm.response.to.have.status(200);
});

四、常见问题(Ubuntu)

❌ 无法启动

./Postman.AppImage --no-sandbox

❌ 请求超时

  • 检查防火墙
  • 确认后端监听 0.0.0.0
  • 使用 127.0.0.1 而非 localhost

❌ HTTPS 证书错误

  • Settings → SSL certificate verification → OFF(仅测试)

如果你有具体调试场景(如:Spring Boot / Node / WebSocket / 文件上传),可以告诉我,我给你更针对性的步骤。

0 踩