curl是非常方便的Rest 客户端, 可以很方便的完成 Rest API测试, 利用curl对http协议发送Get/Post/Delete/Put, 同时还可以携带header 来满足Rest API 需求的特定条件
curl 常用的参数
-X/--request [GET|POST|PUT|DELETE|…] 使用指定的http method发出 http request
-H/--header 设定request里的header
-i/--include 显示response的header
-d/--data 设定 http parameters
-v/--verbose 輸出比较多的信息
-u/--user 使用者账号
-b/--cookie cookie 文件路径 使用cookie
1、get请求
方式一、
curl http://192.168.1.1:8080?user=test001&password=123456
方式二、
curl -i -X GET http://192.168.1.1:8080/bind/getUser?id=123
2、post 请求
方式一、
···
curl -d "user=nickwolfe&password=12345" http://192.168.1.1:8080/login.cgi
···
方式二 、
curl -i -X POST -H 'Content-Type:application/json;charset=UTF-8' --data '{}' http://192.168.1.1:8080/test
方式三、
curl -i -X POST -H 'Content-Type:application/json' --data '{"id":2,"name":"张三","age":18}' \
http://192.168.1.1:8080:8080/testc







网友评论