基本参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| 不带有任何参数时,curl 就是发出 GET 请求。 curl https://www.example.com
-O参数将服务器回应保存成文件,并将 URL 的最后部分当作文件名。 curl -O https://www.example.com/foo/bar.html
-s参数将不输出错误和进度信息。 curl -s https://www.example.com
-S参数指定只输出错误信息,通常与-s一起使用。 curl -s -o /dev/null https://google.com
-L参数会让 HTTP 请求跟随服务器的重定向。curl 默认不跟随重定向。 curl -L -d 'tweet=hi' https://api.twitter.com/tweet
|
指定网卡
1
| curl --interface ppp3 cip.cc
|
参考:https://www.ruanyifeng.com/blog/2019/09/curl-reference.html
CURL命令忽略https请求的SSL证书
1 2
| curl -k https://osetc.com curl --insecure https://www.osetc.com
|
使用curl命令获取文件下载速度
1 2
| curl -Lo /dev/null -skw "%{speed_download}\n" http://mirrors.163.com/ubuntu/ls-lR.gz 226493.000
|
当然,还可以获取连接时间、重定向时间等更多的数据:
1 2 3 4 5 6 7 8
| curl -Lo /dev/null -skw "time_connect: %{time_connect} s\ntime_namelookup: %{time_namelookup} s\ntime_pretransfer: %{time_pretransfer} s\ntime_starttransfer: %{time_starttransfer} s\ntime_redirect: %{time_redirect} s\nspeed_download: %{speed_download} B/s\ntime_total: %{time_total} s\n\n" http://www.sina.com time_connect: 0.154 s time_namelookup: 0.150 s time_pretransfer: 0.154 s time_starttransfer: 0.163 s time_redirect: 0.157 s speed_download: 324679.000 B/s time_total: 1.692 s
|
计算机网络中常用的速率换算关系(B/s vs b/s)
1 2 3 4
| 在计算机网络、IDC机房中,其宽带速率的单位用bps(或b/s)表示;换算关系为:1Byte=8bit 1B=8b ---------- 1B/s=8b/s(或1Bps=8bps) 1KB=1024B ---------- 1KB/s=1024B/s 1MB=1024KB ---------- 1MB/s=1024KB/s
|
计算机网络中常用的速率换算关系(B/s vs b/s)