curl获取响应时间

简介: 1、开启gzip请求curl -I http://www.sina.com.cn/ -H Accept-Encoding:gzip,defalte2、监控网页的响应时间curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_st...
1、开启gzip请求
curl -I http://www.sina.com.cn/ -H Accept-Encoding:gzip,defalte

2、监控网页的响应时间
curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" "http://www.kklinux.com"

3. 监控站点可用性
curl -o /dev/null -s -w %{http_code} "http://www.kklinux.com"

4、以http1.0协议请求(默认为http1.1)
curl -0 ..............


监控站点首页下载时间:

curl -o /dev/null -s -w ‘%{time_total}’ http://www.miotour.com

curl -o /dev/null -s -w ‘%{http_code}’ http://www.miotour.com

curl -o /dev/null -s -w %{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total} http://www.miotour.com

结果:2.547

-s 静默输出;没有-s的话就是下面的情况,这是在脚本等情况下不需要的信息。

[ec2-user@ip-10-122-250-19 ~]$ curl -o /dev/null  -w ‘%{time_total}’ http://www.miotour.com
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100 67770    0 67770    0     0  19228      0 –:–:–  0:00:03 –:–:– 20705
结果:3.524

监控首页各项时间指标:

curl -o /dev/null -s -w ‘%{time_connect}:%{time_starttransfer}:%{time_total}’ http://www.miotour.com

结果:                                                0.244:                             1.044:                         2.672

时间指标解释 :

time_connect    建立到服务器的 TCP 连接所用的时间

time_starttransfer    在发出请求之后,Web 服务器返回数据的第一个字节所用的时间

time_total   完成请求所用的时间

在 发出请求之后,Web 服务器处理请求并开始发回数据所用的时间是

(time_starttransfer)1.044 - (time_connect)0.244 = 0.8 秒

客户机从服务器下载数据所用的时间是

(time_total)2.672 - (time_starttransfer)1.044 = 1.682 秒

指定特定主机IP地址访问网站

curl -x 61.135.169.105:80 http://www.baidu.com

curl -x 61.135.169.125:80 http://www.baidu.com

 

curl用法大全

-x 指定访问IP与端口号

curl -x 192.168.1.1:80  http://www.miotour.com

-I 仅仅取文件的http头部

curl   -I  -x 192.168.1.1:80  http://www.miotour.com

用referer做的防盗链,就可以使用-e来设置

curl -e “http://www.qiecuo.org”    http:// www.miotour.com -v  -I

-H去构造你想要的http头部

curl -H “X-Forward-For:8.8.8.8″ http://www.miotour.com  -v  -I

curl反馈时间,例如连接时间,下载时间等信息

curl -w %{time_connect}:%{time_starttransfer}:%{time_total} -s -o /dev/null

将一个文件保存到硬盘上,命名为file.html

curl -o file.html  http://www.miotour.com/index.html

下载index.html文件, -O是大写的字母

curl -O http://www.miotour.com/index.html

curl提交用户名和密码

curl http://name:passwd@www.miotour.com
curl -u name:passwd http://www.miotour.com

-b “cookie” 此参数用来构造一个携带cookie的请求

目录
相关文章
|
测试技术 Linux
三分钟搞定压力测试之http_load
本文对一个正在云服务器上运行的系统进行一个并发访问的压力测试,以此来模仿真实环境并发访问造成资源带宽不稳定出现的种种问题。
301 0
三分钟搞定压力测试之http_load
|
3天前
|
测试技术 Linux
wrk GET请求压力测试
wrk GET请求压力测试
7 0
|
7月前
|
大数据
什么状况下HTTP代理会访问超时?
什么状况下HTTP代理会访问超时?
|
9月前
|
域名解析 网络协议 网络安全
Curl命令分析接口耗时
Curl是一个非常实用的,用来与服务器之间传输数据的工具,支持的协议包括 (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP),Curl设计为无用户交互下完成工作。
181 0
requests获取响应时间和超时
requests获取响应时间和超时
292 0
requests获取响应时间和超时
|
测试技术 Apache
HTTP 压力测试工具-http_load使用分享
http_load以并行复用的方式运行,用以测试web服务器的吞吐量与负载。 但是它不同于大多数压力测试工具,它可以以一个单一的进程运行,一般不会把客户机搞死。 还可以测试HTTPS类的网站请求。
605 0
|
NoSQL 测试技术 Apache
wrk | 虽小但强!
wrk | 虽小但强!
152 0
|
域名解析 运维 网络协议
如何使用cURL获得请求和响应时间?
今天给大家分享一个干货编程小技巧,上至架构师、下至开发者、运维男、QA, 得此利器,事半功倍。
|
测试技术 网络安全
Slow HTTP POST慢速攻击
测试工具 模拟测试工具:slowhttptest
如何查看HTTP接口的响应时间
WEB测试的过程中,<a href="https://www.fgba.net/" target="_blank">富贵论坛</a>经常会觉得系统慢,但是慢是一个感性的东西,如果这个时候直接找开发理论,开发也可能一脸懵逼,说这个问题不是我的接口,是XX原因,这个时候我们怎么办呢
785 0
如何查看HTTP接口的响应时间