curl發送測試請求

測試rest的時候常用的參數

  • -X 等同於 --request [GET|POST…] 使用指定的http
  • -H 等同於 --head ‘XXX:xxx’ 指定請求參數
  • -i 等同於 --include 顯示response的header
  • -d 等同於 --data 指定http的parameters
  • -v 等同於 --verbose 輸出比較多的信息
  • -u 等同於 --user username:password 使用賬戶密碼
  • -b 等同於 --cookie 使用cookie

發送curl時可以附加的一些信息

  • 設置header : curl -i -H “Content-Type:application/json” http://www.baidu.com
  • 設置http paramter : curl -X POST -d “param1=value1&param2=value2” 或者 -d “param1=value1” -d “param2=value2”
  • session 認證: curl -X GET ‘http://www.badidu.com’ --header ‘sessionid:12342423342342343’
  • 使用cookie : curl -i --header ‘Accept:application/json’ -X GET -b ~/cookie.txt http://www.baidu.com
  • 文件上傳: curl -i -X POST -F ‘file=@/Data/filename.txt’ www.baidu.com
  • 文件下載: curl -O http://localhost:8080/download/xx.txt 下載文件不需要指定文件名,默認同名
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章