在 Ubuntu 上使用 Postman 测试接口,一般有两种方式:
下面从最常用的 图形界面 Postman 讲起。
sudo snap install postman
安装完成后,在应用菜单搜索 Postman 即可打开。
.tar.gz)tar -xzf Postman-linux-x64-*.tar.gz
./Postman/Postman
登录接口)示例:
GET https://api.example.com/users
POST http://localhost:8080/login
在 Params 标签中:
key: page
value: 1
{
"username": "admin",
"password": "123456"
}
常见情况:
Content-Type: application/json
Authorization: Bearer xxxxxxx
点击 Send
返回结果会在下方显示:
假设本地服务:
POST http://127.0.0.1:8000/api/login
Postman 配置:
{
"user": "test",
"pwd": "123"
}
点击 Send,查看返回:
{
"code": 0,
"msg": "success"
}
base_url = http://localhost:8080{{base_url}}/login
如果你用 Postman 导出了 Collection:
sudo npm install -g newman
newman run my_collection.json
sudo snap refresh postman
或检查:
./Postman/Postman --no-sandbox
sudo ufw status
如果你是 测试某个具体接口(如登录 / 上传文件 / WebSocket),可以告诉我接口类型,我可以直接给你 Postman 配置示例。