將 curl 轉換為 Wget

curl2code 將 curl 指令轉換為 Wget 語法。轉換過程透過 WebAssembly 在您的瀏覽器中執行,確保完全隱私。若需 HTTPie,請參考我們的 curl 轉 HTTPie 轉換器。若需原始 HTTP,請參閱 curl 轉 HTTP。下方是實用的 Wget 範例。

如何從瀏覽器複製 curl

  1. 1

    開啟開發者工具 (DevTools)

    按下 F12Ctrl+Shift+I 來開啟您的瀏覽器開發者工具。

  2. 2

    前往網路 (Network) 分頁

    點擊 Network 分頁,並執行觸發 HTTP 請求的操作。

  3. 3

    複製為 cURL

    右鍵點擊該請求 → CopyCopy as cURL。然後將其貼在上方。

常見問題解答

什麼是 Wget?

Wget 是一款非互動式命令列工具,用於從網路下載檔案。它支援 HTTP、HTTPS 與 FTP,具備遞迴下載、鏡像網站以及續傳中斷傳輸等功能。大多數 Linux/macOS 系統皆預裝此工具。curl2code 將 curl 指令轉換為等效的 Wget 語法。

Wget vs curl — 何時該用哪一個?

Wget 擅長下載:遞迴網站鏡像、續傳支援與背景傳輸。curl 更全能:支援更多協定 (25+),具備更好的 API 請求能力,且更易於編寫腳本。下載/鏡像請用 Wget,API 工作請用 curl。另請參閱 curl 轉 HTTPie 獲取現代替代方案。

Wget 如何處理驗證?

對於 Basic 驗證:wget --user=user --password=pass url。對於 Bearer 權杖,使用 --header='Authorization: Bearer token'。Wget 也支援使用 .netrc 檔案儲存憑證:machine host login user password pass。使用 --ask-password 進行互動式密碼輸入。

如何使用 Wget 傳送 POST 資料?

表單資料使用 wget --post-data='key=value&key2=value2' url,檔案內容使用 wget --post-file=data.json url。與 curl 相比,Wget 的 multipart 支援有限 — 對於複雜的上傳,建議使用 curl。curl2code 會將 -d 旗標轉換為 Wget 的 --post-data

如何使用 Wget 處理錯誤?

檢查 Wget 的結束碼:0 (成功)、1 (一般錯誤)、4 (網路失敗)、8 (伺服器錯誤)。使用 --tries=3 進行自動重試,並使用 --waitretry=5 設定重試間隔。Wget 預設將錯誤記錄到 stderr。使用 -o logfile 進行詳細記錄。

如何使用 Wget 進行遞迴下載?

使用 wget -r -l 3 url 遞迴下載最多 3 層深度。加入 -np (no parent) 以保持在該目錄內。-k 轉換連結以便本機檢視,-p 下載所有頁面資產。鏡像網站:wget --mirror -w 2 url。這是 Wget 相對於 curl 的主要優勢。

如何在 Wget 中設定逾時與重試?

連線逾時:--connect-timeout=10。讀取逾時:--read-timeout=30。DNS 逾時:--dns-timeout=5。重試次數:--tries=3 (預設為 20)。重試間隔:--waitretry=5。Wget 內建指數退避機制,重試邏輯比 curl 更強健。

如何在 Wget 中使用代理伺服器 (Proxy)?

透過環境變數設定:export http_proxy=http://proxy:8080。或在 ~/.wgetrc 中設定:http_proxy = http://proxy:8080。命令列方式:wget -e use_proxy=yes -e http_proxy=proxy:8080 url。對於不使用代理的例外:no_proxy = localhost,.internal。curl2code 會將 -x 旗標轉換為 Wget 代理配置。

如何在 Wget 中表示帶有 JSON 主體的 POST 請求?

使用 curl 的 -X POST -d '{"key":"value"}' -H "Content-Type: application/json",curl2code 將會把它轉換為 Wget 格式:wget --post-data='{'key':'value'}' --header='Content-Type: application/json' url。JSON 主體和 Content-Type 標頭會在輸出中保留。curl2code 支援內嵌 JSON 和 @file.json 引用。

如何在 Wget 中包含 Bearer 權杖授權?

當您使用 curl2code 轉換 curl -H "Authorization: Bearer YOUR_TOKEN" URL 時,Bearer 權杖會保留在 Wget 輸出中:wget --header='Authorization: Bearer YOUR_TOKEN' url-H "Authorization: Bearer ..." 和 OAuth 權杖旗標都會被自動偵測。

Content-Type 在 Wget 格式中如何表示?

轉換 curl -H "Content-Type: application/json" URL 時,curl2code 在 Wget 中輸出 Content-Type 為:wget --header='Content-Type: application/json' url。常見類型包括 application/jsonapplication/x-www-form-urlencodedmultipart/form-data。curl2code 會保留原始 curl 指令中確切的 Content-Type。

實用連結

curl 指南

將 curl 轉換為其他語言