1.curlcurl 是常用的命令行工具,同样是linux上可以发送http请求的命令,Postman是一个很好的接口调用管理工具,但是在linux上非curl莫属
常用的参数说明
不带有任何参数时,curl 就是发出 GET 请求。
$ curl https://www.example.com
1.-X:参数指定 HTTP 请求的方法。
2.-d:参数用于发送 POST 请求的数据体。
3.-H:参数添加 HTTP 请求的标头。
4.-k:参数指定跳过 SSL 检测。
5.-L:参数会让 HTTP 请求跟随服务器的重定向。curl 默认不跟随重定向。
6.-b:参数用来向服务器发送 Cookie。
例子
curl -XPOST -k -H ‘Content-Type: application/json;charset=UTF-8’ ‘http://127.0.0.1:80/sp-notified/api/v1/situation-awareness’ -d ‘{“name”:“zhangsan”}’
增加
curl -k -l -H “Content-type: application/json” -X POST -d ‘{
“userId”:“4”,
“userName”:“wangwu”
}’ https://ip:port/url
修改
curl -k -l -H “Content-type: application/json” -X PUT -d ‘{
“userId”:“4”,
“userName”:“wangwu1”
}’ https://ip:port/url/4
删除
curl -k -l -X DELETE https://ip:port/user/4
或者
curl -k -l -X DELETE https://ip:port/user/4,6
查询
curl -k -l -X GET https://ip:port/url