2021年10月18日 星期一

curl 常用語法

 

參考:

https://blog.techbridge.cc/2019/02/01/linux-curl-command-tutorial/

https://www.itread01.com/p/190409.html


應用範例:

curl -X POST -i -H "Content-Type: application/json;charset=utf-8" -d '{"client_id": "test","client_secret": "test"}' "https://localhost:8080/auth"


1.未指定任何參數,預設使用 GET 連線:

curl http://localhost:8080/test.jsp

2.指定使用 POST:

curl -X POST  http://localhost:8080/test.jsp

3.印出 Response Status 資訊:

curl -X POST -i http://localhost:8080/test.jsp

4.指定 Request Header:

curl -H "Content-Type: application/json;charset=utf-8"

5.指定 RequestBody為 JSON(注意JSON內容若使用雙引號,則完成JSON要使用單引號框住):

curl -X POST  -H "Content-Type: application/json;charset=utf-8" -d '{"client_id": "test","client_secret": "test"}' 

6.指定請求RequestBody來源為檔案(檔案路徑前加@):

curl -X POST  -H "Content-Type: application/json;charset=utf-8" -d '@reqt-data.json'

7..指定 HTTP POST  FROM Data:

curl -X POST --data "email=test@example.com&press=%20OK%20"  http://www.example.com/form.php

8.指定使用 cookie:

curl --cookie "name=Jack" http://www.example.com

9.指定 client 公鑰憑證路徑及私鑰 key檔案(應用於 two-way SSL)

curl -E ./client.crt --key client-private.key 'https://test-site/page'

10.連線 HTTPS 並預設信任

curl https://a-site.com/page --insecure





curl 常用語法

  參考: https://blog.techbridge.cc/2019/02/01/linux-curl-command-tutorial/ https://www.itread01.com/p/190409.html 應用範例: curl -X POST -i -H ...