curl [options] [URL…]
-h/–help | 打印幫助信息 |
-V/–version | 顯示版本信息 |
-s/–silent | 靜默模式, 不輸出任何內容 |
-i/–include | 輸出包含 headers 信息 |
-v/–verbose | 輸出詳細內容 |
-#/–progress-bar | 以進度條方式顯示傳輸過程 |
-H/–header LINE (H) | 添加請求頭, 可添加多個 -H 參數, 參數格式: -H “NAME: VALUE” |
-A/–user-agen STRING (H) | 請求頭的 User-Agent 字段 |
-e/–referer URL (H) | 請求頭的 Referer 字段 |
-r/–range RANGE (H) | 請求頭的 Range 字段 |
-b/–cookie STRING/FILE (H) | 請求頭的 Cookie 字段, 以字符串的形式提供, 或從指定 cookie 文件中讀取 |
-c/–cookie-jar FILE (H) | 把響應頭中的 cookie 保存到指定文件 |
-D/–dump-header FILE | 把 headers 信息保存指定文件 |
-I/–head | 只顯示文檔信息(只顯示響應頭) |
-X/–request COMMAND | 執行命令, 如果是 HTTP 則是請求方法, 如: GET, POST, PUT, DELETE 等 如果是 FTP 則是執行 FTP協議命令 |
-d/–data DATA (H) | HTTP POST 請求內容(並自動發出 POST 請求), 例如: aa=bb&cc=dd |
-F/–form CONTENT (H) | HTTP multipart POST 表單數據,(並自動發出 POST 請求) 多個表單字段可添加多個 -H 參數, 如果是文件參數, 路徑值前面需要加@ 參考格式: -F “name1=@/filepath” -F “name2=stringvalue” |
-o/–output FILE FILE | 把響應內容輸出到指定文件 |
-O/–remote-name | 以 URL 的文件名作爲文件名稱保存響應內容到當前目錄 |
-C/–continue-at OFFSET | 斷點續傳, 從 offset 位置繼續傳輸 |
-y/–speed-time SECONDS | 連接 超時時間, 單位: 秒, 默認爲 30 |
-m/–max-time SECONDS | 讀取 超時時間, 必須在該時間內傳輸完數據, 單位: 秒 |
–limit-rate RATE | 限速傳輸, 單位: Byte/s |
-x/–proxy [PROTOCOL://]HOST[:PORT] | 設置代理 |
-U/–proxy-user USER[:PASSWORD] | 代理的用戶名和密碼 |
-u/–user USER[:PASSWORD][;OPTIONS] | 設置服務器的用戶密碼和登錄選項 |
–cacert FILE (SSL) | 使用指定的 CA 證書 |
-P/–ftp-port ADR (F) | 指定 FTP 傳輸的端口 |
-T/–upload-file FILE | 上傳文件到指定的 URL (http/ftp) 位置, 參考格式: -T “file1” 或 -T “{file1,file2}” |
-Q/–quote CMD (F/SFTP) | 執行命令, -X 只執行一條命令, -Q 可執行多條, 多條命令將按順序執行, 參考格式: -Q “cmd1” -Q “cmd2” |
curl -o /dev/null -s -w %{http_code} http://xxx.com
當中的 http_code 代表的意思
$http_code["0"]="Unable to access";
$http_code["100"]="Continue";
$http_code["101"]="Switching Protocols";
$http_code["200"]=”OK”;
$http_code["201"]=”Created”;
$http_code["202"]=”Accepted”;
$http_code["203"]=”Non-Authoritative Information”;
$http_code["204"]=”No Content”;
$http_code["205"]=”Reset Content”;
$http_code["206"]=”Partial Content”;
$http_code["300"]=”Multiple Choices”;
$http_code["301"]=”Moved Permanently”;
$http_code["302"]=”Found”;
$http_code["303"]=”See Other”;
$http_code["304"]=”Not Modified”;
$http_code["305"]=”Use Proxy”;
$http_code["306"]=”(Unused)”;
$http_code["307"]=”Temporary Redirect”;
$http_code["400"]=”Bad Request”;
$http_code["401"]=”Unauthorized”;
$http_code["402"]=”Payment Required”;
$http_code["403"]=”Forbidden”;
$http_code["404"]=”Not Found”;
$http_code["405"]=”Method Not Allowed”;
$http_code["406"]=”Not Acceptable”;
$http_code["407"]=”Proxy Authentication Required”;
$http_code["408"]=”Request Timeout”;
$http_code["409"]=”Conflict”;
$http_code["410"]=”Gone”;
$http_code["411"]=”Length Required”;
$http_code["412"]=”Precondition Failed”;
$http_code["413"]=”Request Entity Too Large”;
$http_code["414"]=”Request-URI Too Long”;
$http_code["415"]=”Unsupported Media Type”;
$http_code["416"]=”Requested Range Not Satisfiable”;
$http_code["417"]=”Expectation Failed”;
$http_code["500"]=”Internal Server Error”;
$http_code["501"]=”Not Implemented”;
$http_code["502"]=”Bad Gateway”;
$http_code["503"]=”Service Unavailable”;
$http_code["504"]=”Gateway Timeout”;
$http_code["505"]=”HTTP Version Not Supported”;
curl返回值000 的可能性
- Failed DNS resolution (6)
- Connection refused (7)
- Connection timed out (28)
- Server actually returns 000 for some reason (0)
參考資料
https://www.cjkuo.net/linux-curl-detail/
https://blog.techbridge.cc/2019/02/01/linux-curl-command-tutorial/
https://www.twblogs.net/a/5c0e2796bd9eee5e4183437e
https://www.796t.com/content/1547802730.html
https://www.cnblogs.com/xkops/p/5614366.html
https://www.cnblogs.com/zqunor/p/6541946.html