Skip to main content

cURL: Tips

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 的信任。 

如何解決信任問題:

  1. 用 Firefox 或 Chrome 下載目的網站的 CA 憑證 *.pem
  2. curl 指定 *.pem  CA 憑證連接網站

curl 要使用特定 CA 憑證檔 *.pem,方法有二:

# 方法一
curl --cacert your-server-ca.pem https://your-server-name

# 方法二
# 

 

 

延伸閱讀