CLI 使用指南
文件版本:20261024
適用於 macOS / Windows 桌面端。iOS 與 Android 沒有這個命令。使用前請先打開 ApiCatcher。
CLI 可以讓 AI 呼叫 ApiCatcher 已有的功能,例如搜尋和分析 HTTP 請求、管理指令碼和重寫規則。
命令在哪裡
用系統自帶的終端來執行。macOS 是「終端機」,Windows 是「命令提示字元」或 PowerShell。
macOS 的命令在已經安裝的應用程式裡面:
/Applications/ApiCatcher.app/Contents/MacOS/apicatcher-cli tools
如果 ApiCatcher 不在「應用程式」資料夾,把 /Applications/ApiCatcher.app 換成你的 ApiCatcher.app。
可以給目前這個終端機視窗起一個短名字,後面就能直接輸入 apicatcher:
alias apicatcher="/Applications/ApiCatcher.app/Contents/MacOS/apicatcher-cli"
Windows 到 ApiCatcher 的安裝資料夾裡,執行裡面的 apicatcher-cli.exe。預設位置是:
%LOCALAPPDATA%\Programs\ApiCatcher\apicatcher-cli.exe tools
桌面上的 ApiCatcher 圖示是視窗程式,不是這條命令。
後面的例子都寫成 apicatcher。請換成你電腦上的實際路徑。
應用程式必須已經打開,並且打開了 CLI
CLI 預設關閉,不會占用連接埠。要讓命令可用:
- 打開 ApiCatcher。
- 在側欄打開 CLI,打開開關。
- 完全退出應用程式,再重新打開。這次啟動才會在這台電腦上接受命令。
關掉開關後,同樣要到下次啟動才停止。
應用程式沒打開、開關沒打開,或改完開關還沒重新啟動時,命令會失敗。
命令
查看目前版本的工具和參數。以這條命令的輸出為準。
apicatcher tools
呼叫一個工具。--args 是一個 JSON 物件。
apicatcher call search_requests --args '{"host":"api.example.com","limit":10}'
也可以從標準輸入讀參數:
printf '%s' '{"host":"api.example.com"}' | apicatcher call search_requests
沒有傳 --args,而且標準輸入是終端時,參數是 {}。沒有參數的工具可以直接呼叫:
apicatcher call get_capture_status
輸出
標準輸出只有一個 JSON 物件。成功或失敗看 ok。工具結果本身是 JSON 時放在 result,否則 result 是字串。
{"ok":false,"error":"ApiCatcher is not running"}
search_requests 常用參數:keyword、search_target(url、host、req_header、resp_header、req_body、resp_body)、method、host、status_code、file_type、session_id、limit、skip。
安全
- 命令只在這台電腦上可用,區域網路裡的其他裝置連不上。
- 命令讀到的是真實抓包內容,可能包含 Cookie、權杖和請求本體。不要把輸出發到公開場合。