1. 发送 post 请求(请求参数为 json 格式):
curl -i -X POST -H 'Content-type':'application/json' -d '{"id":"'7'","token":"'LzvKzJ'"}' url地址
# 不带请求头
curl -v -XPOST url地址 -d 'name=张三&age=14'
2. 发送 get 请求:
curl https://localhost:8080/user/getInfo?id=7\&userName=Janet
注:请求有多个参数时,& 之前要加转义符
3. 获取请求结果
把结果输出到一个文件中,再读取文件即可。
$ curl http://localhost:60001/api/measures/search?projectKeys=org.example:JanetTestProject\&metricKeys=bugs > result.log
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 105 100 105 0 0 2337 0 --:--:-- --:--:-- --:--:-- 2386
$ cat result.log
{"measures":[{"metric":"bugs","value":"4","component":"org.example:JanetTestProject","bestValue":false}]}[
cut命令:
对result.log按照“,” 进行分割,并输出分割后第2列信息
$ cat result.log
{"measures":[{"metric":"bugs","value":"4","component":"org.example:JanetTestProject","bestValue":false}]}
$ cut -d "," -f 2 result.log
"value":"4"
$ cut -d '"' -f 10 result.log
4
awk 分割:
$ echo $(curl http://10.142.143.230:60001/api/measures/search?projectKeys=org.example:JanetTestProject\&metricKeys=bugs) | awk -F '"' '{print $10}'
4
$ echo "111||222|333"|awk 'BEGIN{FS="[|]+"}{print $1}'
111