Postman在Ubuntu上的安装方式主要有三种,推荐使用Snap包或手动下载(二进制包)安装:
Snap包安装(最简方式):
打开终端,依次执行以下命令更新系统、安装Snap包管理器并安装Postman:
sudo apt update
sudo apt install snapd
sudo snap install postman
安装完成后,终端输入postman即可启动应用。
手动下载安装(二进制包):
若需自定义安装路径,可通过以下步骤完成:
① 终端执行wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz下载最新版Postman;
② 解压安装包:tar -xvf postman.tar.gz;
③ 移动解压后的文件夹至/opt目录:sudo mv Postman /opt;
④ 创建符号链接以便终端直接调用:sudo ln -s /opt/Postman/Postman /usr/local/bin/postman;
⑤ (可选)创建桌面启动器图标:编辑/usr/share/applications/postman.desktop文件,添加以下内容:
[Desktop Entry]
Encoding=UTF-8
Name=Postman
Exec=postman
Icon=/opt/Postman/app/resources/app/assets/icon.png
Terminal=false
Type=Application
Categories=Development;
保存后,即可在应用程序菜单中找到Postman。
GET、POST、PUT、DELETE等HTTP方法(根据API需求调整);https://api.example.com/users/1);Content-Type: application/json、Authorization: Bearer {token},其中{token}为动态变量);POST/PUT等需要发送数据的请求,切换至“Body”选项卡,选择格式(如raw→JSON),输入请求体(如{"name": "John", "age": 30})。Content-Type: application/json);// 验证状态码是否为200
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
// 验证响应体中"name"字段是否为"John"
pm.test("Name is John", function () {
const jsonData = pm.response.json();
pm.expect(jsonData.name).to.eql("John");
});
断言结果将显示在“Test Results”面板中(通过/失败)。base_url、token),可创建环境变量:base_url: https://api.example.com、token: your_access_token);${variable_name}引用(如URL填写${base_url}/users/1,Headers中填写Authorization: Bearer ${token})。通过以上步骤,可在Ubuntu系统上高效使用Postman调试API,覆盖从基础请求到自动化测试的全流程。