curl
是一個用于在命令行中進行網絡請求的工具。以下是一些 curl
命令的常見用法:
-
從 URL 下載文件并保存為本地文件:
curl -O URL
例如:
curl -O https://example.com/file.zip
這將會將
file.zip
下載到當前目錄。 -
將文件下載到指定位置:
curl -o OUTPUT_PATH URL
例如:
curl -o local_file.zip https://example.com/file.zip
這將會將
file.zip
下載并保存為local_file.zip
。 -
顯示 HTTP 頭信息:
curl -I URL
例如:
curl -I https://example.com
這將會顯示
example.com
的 HTTP 頭信息。 -
顯示響應內容:
curl URL
例如:
curl https://example.com
這將會顯示
example.com
的響應內容。 -
使用 POST 請求發送數據:
curl -X POST -d "key1=value1&key2=value2" URL
例如:
curl -X POST -d "username=admin&password=12345" https://example.com/login
這將會發送 POST 請求,攜帶參數
username=admin
和password=12345
。 -
使用基本認證進行請求:
curl -u username:password URL
例如:
curl -u admin:12345 https://example.com/api/data
這將使用用戶名
admin
和密碼12345
進行請求。 -
使用代理進行請求:
curl -x proxy_host:proxy_port URL
例如:
curl -x http://proxy.example.com:8080 https://example.com
這將通過指定的代理服務器
proxy.example.com
和端口8080
發起請求。