在 Ubuntu 上使用 Postman 调试接口,一般有两种方式:
下面一步一步说明。
sudo snap install postman
安装完成后,在应用菜单搜索 Postman 即可打开。
tar -xvf Postman-linux-x64-*.tar.gz
./Postman/Postman
GETPOSTPUTDELETE例如:
http://localhost:8080/api/user
Content-Type: application/json)raw → JSON{
"username": "test",
"password": "123456"
}
点击 Send
如果是本地服务:
curl http://localhost:8080/api/test
再用 Postman 对照调试
base_url = http://localhost:8080
{{base_url}}/api/user
pm.environment.set("token", "abc123");
pm.test("状态码是200", function () {
pm.response.to.have.status(200);
});
适合 CI / 服务器环境
sudo snap install newman
# 或
npm install -g newman
Postman → 集合 → Export
newman run example.postman_collection.json
sudo apt install libnss3
127.0.0.1 而不是 localhost如果你有 具体接口类型(Java / Python / Node) 或 报错信息,可以贴出来,我可以帮你更精准地调试。