国产成人精品999视频&日本一区二区亚洲人妻精品&久久久精品国产99久久精&99热这里只有成人精品国产&精品国产剧情av一区二区&成人亚洲精品久久久久app&国产精品美女高潮抽搐A片

Curl 備忘清單

Curl 備忘清單包含命令和一些常見(jiàn)的 Curl 技巧示例。

入門

介紹

Curl 是一種在服務(wù)器之間傳輸數(shù)據(jù)的工具,支持協(xié)議,包括 HTTP/FTP/IMAP/LDAP/POP3/SCP/SFTP/SMB/SMTP 等

Options

-o <file>    # --output: 寫入文件
-u user:pass # --user: 驗(yàn)證

-v           # --verbose: 在操作期間使 curl 冗長(zhǎng)
-vv          # 更冗長(zhǎng)
-s           # --silent: 不顯示進(jìn)度表或錯(cuò)誤
-S           # --show-error: 與 --silent (-sS) 一起使用時(shí),顯示錯(cuò)誤但沒(méi)有進(jìn)度表

-i           # --include: 在輸出中包含 HTTP 標(biāo)頭
-I           # --head: 僅標(biāo)頭

請(qǐng)求

-X POST # --request
-L  # 如果頁(yè)面重定向,請(qǐng)點(diǎn)擊鏈接
-F  # --form: multipart/form-data 的 HTTP POST 數(shù)據(jù)

數(shù)據(jù)

# --data: HTTP post 數(shù)據(jù)
# URL 編碼(例如,status="Hello")
-d 'data'

# --data 通過(guò)文件
-d @file

# --get: 通過(guò) get 發(fā)送 -d 數(shù)據(jù)
-G

頭信息 Headers

-A <str>         # --user-agent

-b name=val      # --cookie

-b FILE          # --cookie

-H "X-Foo: y"    # --header

--compressed     # 使用 deflate/gzip

SSL

    --cacert <file>
    --capath <dir>
-E, --cert <cert>     # --cert: 客戶端證書文件
    --cert-type       # der/pem/eng
-k, --insecure        # 對(duì)于自簽名證書

安裝

apk add --update curl  # alpine linux 中安裝

示例

CURL GET/HEAD

命令說(shuō)明
curl -I https://www.baidu.comcurl 發(fā)請(qǐng)求
curl -v -I https://www.baidu.com帶有詳細(xì)信息的 curl 發(fā)請(qǐng)求
curl -X GET https://www.baidu.com使用顯式 http 方法進(jìn)行 curl
curl --noproxy 127.0.0.1 http://www.stackoverflow.com沒(méi)有 http 代理的 curl
curl --connect-timeout 10 -I -k https://www.baidu.comcurl 默認(rèn)沒(méi)有超時(shí)
curl --verbose --header "Host: www.mytest.com:8182" www.baidu.comcurl 得到額外的標(biāo)題
curl -k -v https://www.google.comcurl 獲取帶有標(biāo)題的響應(yīng)

多文件上傳

$ curl -v -include \
    --form key1=value1 \
    --form upload=@localfilename URL

為 curl 響應(yīng)美化 json 輸出

$ curl -XGET http://${elasticsearch_ip}:9200/_cluster/nodes | python -m json.tool

CURL POST

命令說(shuō)明
curl -d "name=username&password=123456" <URL>curl 發(fā)請(qǐng)求
curl <URL> -H "content-type: application/json" -d "{ \"woof\": \"bark\"}"curl 發(fā)送 json

CURL 腳本安裝 rvm

curl -sSL https://get.rvm.io | bash

CURL 高級(jí)

命令說(shuō)明
curl -L -s http://ipecho.net/plain, curl -L -s http://whatismijnip.nl獲取我的公共 IP
curl -u $username:$password http://repo.dennyzhang.com/README.txt帶憑證的 curl
curl -v -F key1=value1 -F upload=@localfilename <URL>curl 上傳
curl -k -v --http2 https://www.google.com/使用 http2 curl
curl -T cryptopp552.zip -u test:test ftp://10.32.99.187/curl ftp 上傳
curl -u test:test ftp://10.32.99.187/cryptopp552.zip -o cryptopp552.zipcurl ftp 下載
curl -v -u admin:admin123 --upload-file package1.zip http://mysever:8081/dir/package1.zip使用憑證 curl 上傳

檢查網(wǎng)站響應(yīng)時(shí)間

curl -s -w \
     '\nLookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nAppCon time:\t%{time_appconnect}\nRedirect time:\t%{time_redirect}\nPreXfer time:\t%{time_pretransfer}\nStartXfer time:\t%{time_starttransfer}\n\nTotal time:\t%{time_total}\n' \
     -o /dev/null https://www.google.com

使用 Curl 檢查遠(yuǎn)程資源是否可用

curl -o /dev/null --silent -Iw "%{http_code}" https://example.com/my.remote.tarball.gz

正在下載文件

curl https://example.com | \
grep --only-matching 'src="[^"]*.[png]"' | \
cut -d\" -f2 | \
while read i; do curl https://example.com/"${i}" \
-o "${i##*/}"; done

從站點(diǎn)下載所有 PNG 文件(使用GNU grep)

下載文件,保存文件而不更改其名稱

curl --remote-name "https://example.com/linux-distro.iso"

重命名文件

curl --remote-name "http://example.com/index.html" --output foo.html

繼續(xù)部分下載

curl --remote-name --continue-at - "https://example.com/linux-distro.iso"

從多個(gè)域下載文件

curl "https://www.{example,w3,iana}.org/index.html" --output "file_#1.html"

下載一系列文件

curl "https://{foo,bar}.com/file_[1-4].webp" --output "#1_#2.webp"

下載一系列文件(輸出foo_file1.webpfoo_file2.webp…bar_file1_webp等)

將輸出重定向到文件

$ curl http://url/file > file

基本認(rèn)證

$ curl --user username:password http://example.com/
$ curl -u username:password http://example.com/

寫入文件而不是標(biāo)準(zhǔn)輸出

$ curl -o file http://url/file
$ curl --output file http://url/file

下載頭信息

$ curl -I url
# 顯示頭信息

將輸出寫入名為遠(yuǎn)程文件的文件

$ curl -o file http://url/file
$ curl --output file http://url/file

執(zhí)行遠(yuǎn)程腳本

$ curl -s http://url/myscript.sh

配置文件

curl -K file
# 從文件中讀取配置
curl --config file
$HOME/.curlrc # 類 UNIX 系統(tǒng)中的默認(rèn)配置文件