在 Ubuntu 里用 Postman 调试接口,通常分为「安装 / 启动」和「调试技巧」两部分。下面按实用场景给你说明。
snap install postman
启动:
postman
或在应用菜单搜索 Postman
tar -xvf Postman-linux-x64-*.tar.gz
./Postman/Postman
GET / POST / PUT / DELETEhttp://localhost:8080/api/user
raw → JSON{
"username": "test"
}
curl http://localhost:8080
127.0.0.1 和 localhost 混用(有时 Docker 环境不同)如果 Postman 在宿主机:
http://localhost:容器映射端口
如果 Postman 在容器中,用:
http://容器名:端口
Ubuntu 下可能报错:
SSL certificate error
解决:
Ctrl + Alt + Cconsole.log("token:", pm.environment.get("token"));
pm.test("状态码是200", function () {
pm.response.to.have.status(200);
});
在 Postman Console 中查看 console.log 输出。
devbase_url = http://localhost:8080
{{base_url}}/api/user
切换环境即可调试不同服务器。
| 问题 | 解决 |
|---|---|
| 打不开 Postman | 用 ./Postman/Postman 看报错 |
| 请求超时 | 检查防火墙 / 端口 |
| CORS 错误 | 后端加 CORS,或关浏览器安全模式 |
| 中文乱码 | Response → Pretty → UTF-8 |
如果你愿意,可以告诉我:
我可以给你更针对性的 Postman 调试方案。