Software engineering notes

Linux curl

-i -I 顯示 response 的 detail

只顯示 header

curl -I http://wwww.example.com

顯示 header + body

curl -i http://wwww.example.com

-H 指定 Header

curl -H "Authorization:Bearer NDQzYmM1ZD" http://www.example.com

-D 將 response 的 header 輸出成檔案

curl www.google.com -D /tmp/google-cookie.txt

v 顯示 request/reqsponse 的 request detail

curl -v http://wwww.example.com

-L support 302 redirect

$ curl -L www.google.com

-x 指定 proxy

curl -x proxy.example2.com:8080 http://www.example.com
curl -b cookie.txt http://www.example.com

-e Referrer (若該網站限制需先訪問網站首頁才能訪問下載頁)

curl -e "www.example.com" http://download.example.com

支援 Regex

curl -O http://www.example.com/img0[1-9].jpg

-o 指定下載的檔案名稱

curl -o test.mp4 http://www.example.com/static/test-3841.mp4

-u 指定帳號密碼

curl -u name:passwd ftp://ftp.example.com:13688/path

相當於 $ curl ftp://name:passwd@ftp.example.com:13688/path

-d POST

curl -d "user=robin&password=1234" http://example.com/update_user

-T PUT

curl -X PUT -d "payload" http://localhost
curl -T test.mp4 http://example.com/update_video

-d @{file_path} body referred to file

curl -X PUT -d @/tmp/test.log http://example.com/update_user
curl -X POST -d @/tmp/test.log http://example.com/update_user