cURL
cURL是一個開源專案,主要的產品是curl和libcurl,兩者功能均是:基於網路協定,對指定URL進行網路傳輸。 cURL涉及是任何網路協定傳輸,不涉及對具體資料的具體處理。
Tips
Cheat Sheet
Options in the integration with Shell
CURL_CMD="curl"
CURL_OPT="-qSfs -m 60"
CURL_OPT_POST="-qSfs -m 60 -X POST"
POST Request
Send an Empty POST Request
curl -X POST https://catonmat.net
Send a POST Request with Form Data
curl -d 'login=emma&password=123' -X POST https://google.com/login
GET Request
Send a GET Request and Print the Response to Screen
curl https://catonmat.net/api?a=1&b=2
Send a GET Request and Save the Response to a File
curl -o response.txt https://catonmat.net/api?a=1&b=2
Self-Signed Certificate
Error: curl: (60) SSL certificate problem: unable to get local issuer certificate
用 curl 連線 HTTPS 網站時,如遇到 self-signed certificate 類型或有些網站憑證,在瀏覽器上顯示是安全;在 curl 會出現錯誤訊息。原因是網站的簽發者憑證不受用戶端 curl 的信任。
如何解決信任問題:
- 用 Firefox 或 Chrome 下載目的網站的簽發者 CA 憑證 *.pem
- curl 指定 *.pem CA 憑證連接網站
curl 要使用特定 CA 憑證檔 *.pem,方法有二:
# 方法一
curl --cacert your-server-ca.pem https://your-server-name
# 方法二
# 先找出 curl 的 CApath, 隨便設定一個錯誤的 CA file
curl --cacert XXX https://your-server-name
curl: (77) error setting certificate verify locations:
CAfile: xxx
CApath: /etc/ssl/certs <===
# 在 CApath 裡有一個檔案 ca-certificates.crt , 這用來信任那些客製的憑證
# 從檔案最底端加上新的憑證
# 加入的憑證一旦信任成功,curl 就不再需要指定 CA file
cat your-server-ca.pem >> /etc/ssl/certs/ca-certificates.crt
curl https://your-server-name
HTTP Status Codes
Use a Proxy
curl -x username:Password@myproxy.com:8080 https://catonmat.net
Download
curl --request GET \
--url 'https://www.tenable.com/downloads/api/v2/pages/nessus/files/Nessus-10.5.1-es9.x86_64.rpm' \
--output 'Nessus-10.5.1-es9.x86_64.rpm'
Online Tools
More online tools
Public IP
Web Online
↪ curl ifconfig.me
219.68.222.111⏎
↪ curl ifconfig.me/ip
219.68.222.111⏎
↪ curl ip.im
↪ curl ipv4.im
↪ curl ip.im/info
↪ curl ip.im/8.8.8.8
curl ifconfig.co
curl checkip.amazonaws.com
curl icanhazip.com
curl ipecho.net/plain
curl -Ls myip.check.place
CryptoCurrency
curl rate.sx
curl rate.sx/btc
curl rate.sx/btc@3d # for last 3 days
curl rate.sx/1btc # convert 1 BTC to ?? USD
curl rate.sx/:help
Weather
curl wttr.in
curl wttr.in/TaoYuan
curl wttr.in/:help
QRcode
curl qrenco.de
curl qrenco.de/www.yutube.com
curl qrenco.de/:help
printf "$@" | curl -F-=\<- qrenco.de
Shorten URL
curl -F 'shorten=https://www.osslab.tw' https://0x0.st
Tinyurl.com: short URL from the terminal
echo https://URL | xargs -r -I {} curl -s -d url={} -G https://tinyurl{.}com/create.php | \
awk '/indent/ {print substr($2,19,39)}' | sed '2!d' | sed 's/<.*//'
Learning cURL
- Basics of HTTP Requests with cURL: An In-Depth Tutorial
- Curl Cookbook
- Httpie - Alternative to Curl