在 Ubuntu 上用 Postman 调试接口,常见使用方式和调试技巧如下:
sudo snap install postman
tar -xzf Postman-linux-x64-*.tar.gz
cd Postman
./Postman
GET / POST / PUT / DELETEhttp://localhost:8080/api/test)http://example.com/api?page=1&size=10
或在 Params 中填写
常见调试 Header:
Content-Type: application/json
Authorization: Bearer token
raw → JSON{
"username": "test",
"password": "123456"
}
发送请求后,检查:
打开 Postman Console:
Ctrl + Alt + CView → Show Postman Console可以看到:
✅ 接口没反应、404、CORS 问题,先看 Console
适合多环境(dev / test / prod)
{{base_url}}/api/login
设置变量:
Environments → Addbase_url = http://localhost:8080
在请求发送前执行 JS:
console.log("准备发送请求");
pm.environment.set("token", "abc123");
pm.test("状态码是 200", function () {
pm.response.to.have.status(200);
});
pm.test("返回数据包含 token", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.token).to.exist;
});
127.0.0.1 而不是 localhostSettings → General → SSL certificate verification → OFF
curl 对比:curl -X POST http://localhost:8080/api/login \
-H "Content-Type: application/json" \
-d '{"user":"test"}'
如果你愿意,可以告诉我:
我可以给你更针对性的调试方案 ✅