curl [option] [url]
注意 url 一定要帶引號,否則url參數不能全部傳遞成功
-A <string> 設置用戶代理
-b <name=string/file> 包含cookie的字符串或文件
-c <file> 操作結束后把cookie寫入到這個文件中
-o <file> 將輸出寫入到這個文件 也可以使用重定向 > file
-T <file> 上傳文件
-x <host:port> 使用代理網址
-X <GET/POST> 指定請求方式
-i 顯示響應頭部信息
-d POST請求傳遞的數據, 如果數據再json文件中, -d @test.json
-H 設置請求頭
示例:
curl -i -XGET "http://www.baidu.com"
curl -i -XPOST "http://127.0.0.1/create_user" -d '{"name":"xxx", "age":23}'
test.json
{"name":"xxx", "age":23}
curl -i -XPOST "http://127.0.0.1/create_user" -d @test.json
設置請求頭
curl -i -XPOST "http://127.0.0.1/create_user" -d '{"name":"xxx", "age":23}' -H "Content-Type: application/json"