Postman在CentOS上的使用技巧
sudo rpm -Uvh https://dl.pstmn.io/download/latest/linux/x64/yum/yum.repo),然后通過sudo yum install postman命令安裝,安裝后直接通過postman命令啟動。sudo yum install snapd && sudo systemctl enable --now snapd.socket),再通過sudo snap install postman --classic安裝,啟動命令同上。/opt目錄(sudo tar zxvf Postman-linux-x64-*.tar.gz -C /opt),創建符號鏈接(sudo ln -s /opt/Postman/Postman /usr/bin/postman)以便終端直接運行。/usr/share/applications/postman.desktop文件,添加以下內容可生成桌面圖標,方便圖形界面啟動:[Desktop Entry]
Encoding=UTF-8
Name=Postman
GenericName=Api Tools
Comment=Postman
Exec=/usr/bin/postman
Terminal=false
MimeType=text/plain
Icon=/opt/Postman/app/resources/app/assets/icon.png
StartupNotify=true
Categories=Development;
賦予執行權限(sudo chmod +x /usr/share/applications/postman.desktop)。BASE_URL、API_KEY),在請求URL或Headers中使用{{variable_name}}引用(如https://{{BASE_URL}}/api/users),避免硬編碼敏感信息。COMMON_TOKEN),適用于所有環境,方便共享通用配置。Content-Type: application/json),切換至“Body” tab選擇“raw”格式輸入JSON數據(如{"name": "John", "email": "john@example.com"}),點擊“Send”發送請求。pm.environment.set("timestamp", new Date().toISOString()),之后可在請求URL或Headers中使用{{timestamp}}。pm.test("Status code is 200", function() { pm.response.to.have.status(200); }))、響應體是否包含特定字符串(pm.test("Body contains success", function() { pm.expect(pm.response.text()).to.include("success"); }))。sudo yum install nodejs npm && sudo npm install -g newman),使用命令運行Postman集合(newman run my_collection.json),支持參數化(--env-var "BASE_URL=https://api.example.com")和生成HTML報告(--reporters html),實現API測試自動化。Cache-Control: no-cache,確保獲取服務器最新響應,避免緩存干擾測試結果。top、htop工具監控Postman運行時的CPU、內存占用,若資源不足,關閉不必要的后臺進程釋放資源。net.ipv4.tcp_fin_timeout、net.ipv4.tcp_tw_reuse)提升網絡性能。