發(fā)起GET 請求
curl -u username https://api.github.com/user?access_token=XXXXXXXXXX
發(fā)起POST 請求
# POST
curl -u username --data "param1=value1¶m2=value" https://api.github.com
curl -X POST -H "Content-Type:application/json" --data "{\"type\": \"shell_command\", \"command\": \"create_chunk.py '{\\\"pbdId\\\": 12321,\\\"chunkInfo\\\":[{\\\"diskId\\\":1,\\\"chunkNo\\\":0,\\\"version\\\":0}, {\\\"diskId\\\":1,\\\"chunkNo\\\":1,\\\"version\\\":0}]}'\"}" http://11.160.27.10:3842/api/v1/hosts/e07e10230.eu6sqa/task_block
# 也可以指定一個文件,將該文件中的內(nèi)容當(dāng)作數(shù)據(jù)傳遞給服務(wù)器端
curl --data @filename https://github.api.com/authorizations
# --data-urlencode,通過該選項提供的參數(shù)會自動轉(zhuǎn)義特殊字符。
curl --data-urlencode "value 1" http://hostname.com
可以通過 -X 選項指定其它協(xié)議
curl -I -X DELETE https://api.github.cim
發(fā)起跨域訪問請求
curl -H "Origin: http://example.com" \
-H "Referer: http://example.com" \
-H "Access-Control-Request-Method: GET" \
-X OPTIONS --verbose \
http://10.189.196.146:9201/api/data/activity/search/findByWorkflowIdOrderByGmtCreateAsc?workflowId=0231bf6e-56b0-4fef-83e2-c2c38050b284
常見使用方式
-v 顯示請求的信息
-X 選項指定其它協(xié)議
GET請求方式
# curl -v 172.16.60.21:8080/caijin/age/18
POST請求方式
# curl -v 172.16.60.21:8080/caijin -d 'age=14&cupSize=C'
# curl -v -X POST 172.16.60.21:8080/caijin -d 'age=14&cupSize=C'
PUT請求方式
# curl -v -X PUT -d "age=19&cupSize=C" 172.16.60.21:8080/caijin/3
# curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"message":"aaaa","exchange_id":"123" }' 'http://localhost:9090/service/record'
DELETE請求方式
# curl -v -X DELETE 172.16.60.21:8080/caijin/3