CentOS系統下Swagger接口測試方法
Swagger UI是CentOS環境下最常用的接口測試工具,提供可視化的文檔展示和實時請求響應功能。
http://<服務器IP>:8080/swagger-ui.html
,若為遠程訪問需替換為公網IP或域名),即可打開交互式API文檔頁面。cURL是Linux系統自帶的命令行工具,適合快速測試接口,無需圖形界面。
curl "http://<服務器IP>:<端口>/<接口路徑>?param1=value1¶m2=value2"
;curl -X POST "http://<服務器IP>:<端口>/<接口路徑>" -H "Content-Type: application/x-www-form-urlencoded" -d "param1=value1¶m2=value2"
;curl -X POST "http://<服務器IP>:<端口>/<接口路徑>" -H "Content-Type: application/json" -d '{"key1":"value1","key2":"value2"}'
;curl -X POST "http://<服務器IP>:<端口>/<接口路徑>" -F "file=@/path/to/local/file" -F "param1=value1"
。swagger.json
);導入后,SoapUI會自動生成接口列表,點擊接口旁的綠色三角按鈕即可發送請求,支持斷言(如狀態碼、響應內容)和參數化測試。swagger-hacker.py
腳本;在CentOS終端中運行python3 swagger-hacker.py -u <Swagger JSON地址>
(如python3 swagger-hacker.py -u http://<服務器IP>:<端口>/v2/api-docs
);腳本會自動發送請求并生成測試報告,包含接口的響應狀態、耗時等信息。接口測試需兼顧安全性,可使用Burp Suite或X-Ray等工具掃描Swagger接口的潛在漏洞(如SQL注入、XSS攻擊)。
http://127.0.0.1:8080
),將流量轉發到Burp Suite或X-Ray;