#! /bin/bash
#
URL='http://192.168.20.127/cgi-bin/lig_switch.cgi'
cat <<EOF | while read line
query={"name":"switch","data":{"attribute_name":"port","type":"v","index":0}}
query={"name":"switch","data":{"attribute_name":"xxx","type":"v","index":0}}
query={"name":"switch","data":{"type":"v","index":0}}
query={"name":"switch","data":{"attribute_name":"routing","type":"v","index":0}}
query={"name":"switch","data":{"attribute_name":"xxx","type":"v","index":0}}
query={"name":"switch","data":{"xxx":"routing","type":"v","index":0}}
query={"name":"switch","data":{"attribute_name":"port_cfg","type":"v","index":1}}
query={"name":"switch","data":{"attribute_name":"xxx","type":"v","index":1}}
query={"name":"switch","data":{"xxxxx":"port_cfg","type":"v","index":1}}
update={"name":"switch","data":{"port_cfg":{"index":1,"dir":"in","type":"v","title":"ROOM-SIG_1","HDCP_mode":{"sid":155,"value":0}}}}
update={"name":"switch","data":{"xxx":{"index":1,"dir":"in","type":"v","title":"ROOM-SIG_1","HDCP_mode":{"sid":155,"value":0}}}}
update={"name":"switch","data":{"port_cfg":{"index":1,"dir":"out","type":"v","title":"ROOM-TV-1","SwitchSpeed":{"sid":75,"value":1}}}}
update={"name":"switch","data":{"12345456":{"index":1,"dir":"out","type":"v","title":"ROOM-TV-1","SwitchSpeed":{"sid":75,"value":1}}}}
EOF
do
echo -e "\e[32;1m$line\e[0m "
curl --silent -G --data $line ${URL} | json_pp -f json -t json
done
curl -i -G --trace-time --data ‘query={“name”:“switch”,“data”:{“attribute_name”:“port_cfg”,“type”:“v”,“index”:1}}’ http://192.168.20.127/cgi-bin/lig_switch.cgi -o log
-i/–include 输出时包括protocol头信息
-G/–get 以get的方式来发送数据
–trace 对指定文件进行debug
–trace-ascii Like --跟踪但没有hex输出
–trace-time 跟踪/详细输出时,添加时间戳
–data
-o/–output 把输出写到该文件中
-O/–remote-name 把输出写到该文件中,保留远程文件的文件名
-d/–data HTTP POST方式传送数据
–data-ascii 以ascii的方式post数据
–data-binary 以二进制的方式post数据
–negotiate 使用HTTP身份验证
–digest 使用数字身份验证
–disable-eprt 禁止使用EPRT或LPRT
–disable-epsv 禁止使用EPSV
curl -G --data 'query={"name":"switch","data":{"attribute_name":"port_cfg","type":"v","index":1}}' http://192.168.20.127/cgi-bin/lig_switch.cgi | json_pp
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 117 0 117 0 0 5625 0 --:--:-- --:--:-- --:--:-- 5850
{
"status" : "failed",
"name" : "switch",
"data" : {
"test" : "for example",
"index" : 1,
"type" : "v",
"attribute_name" : "port_cfg"
}
}
可以在git bash中运行(windows)
curl --silent -G --data 'query={"name":"switch","data":{"attribute_name":"port_cfg","type":"v","index":1}}' http://192.168.20.127/cgi-bin/lig_switch.cgi | json_pp -f json -t json
{
"data" : {
"attribute_name" : "port_cfg",
"test" : "for example",
"type" : "v",
"index" : 1
},
"name" : "switch",
"status" : "failed"
}
1、vim curl
\n
time_namelookup: %{time_namelookup}\n
time_connect: %{time_connect}\n
time_appconnect: %{time_appconnect}\n
time_pretransfer: %{time_pretransfer}\n
time_redirect: %{time_redirect}\n
time_starttransfer: %{time_starttransfer}\n
----------\n
time_total: %{time_total}\n
\n
time_namelookup:DNS解析域名时间,把域名—>ipd的时间
time_connect:TCP连接的时间,三次握手的时间
time_appconnect:SSL|SSH等上层连接建立的时间
time_pretransfer:从请求开始到到响应开始传输的时间
time_redirect:从开始到最后一个请求事务的时间
time_starttransfer:从请求开始到第一个字节将要传输的时间
time_total:总时间
2、eg
curl -w "@curl.conf" --silent -G --data 'query={"name":"switch","data":{"attribute_name":"port_cfg","type":"v","index":1}}' http://192.168.20.127/cgi-bin/lig_switch.cgi
{"status":"failed","name":"switch","data":{"attribute_name":"port_cfg","index":1,"test":"for example","type":"v"}
}
time_namelookup: 0.000001
time_connect: 0.015000
time_appconnect: 0.000000
time_pretransfer: 0.015000
time_redirect: 0.000000
time_starttransfer: 0.031000
----------
time_total: 0.031000
3、简单的方式
curl -o /dev/null -s -w '%{time_connect}:%{time_starttransfer}:%{time_total}\n' 'http://www.baidu.com'
4、 post方式传输文件
curl -i -X POST --trace-time http://192.168.20.110/cgi-bin/upload.cgi -F "file=@//home/alex/Git_repo/CPMS-34/VS-34FD_xx.xx.xxxx.kptw" -v