接口测试时候经常需要定位访问慢的原因,是dns还是接口返回慢还是加载慢?强大的curl提供的详细的功能。文档地址:
Available --write-out variables
Some of these variables are not available in really old curl versions.
%{content_type} shows the Content-Type of the requested document, if there was any.
%{filename_effective} shows the ultimate filename that curl writes out to. This is only meaningful if curl is told to write to a file with the--remote-nameor--outputoption. It's most useful in combination with the--remote-header-nameoption.
%{ftp_entry_path} shows the initial path curl ended up in when logging on to the remote FTP server.
%{response_code} shows the numerical response code that was found in the last transfer.
%{http_connect} shows the numerical code that was found in the last response (from a proxy) to a curl CONNECT request.
%{local_ip} shows the IP address of the local end of the most recently done connection—can be either IPv4 or IPv6
%{local_port} shows the local port number of the most recently made connection
%{num_connects} shows the number of new connects made in the recent transfer.
%{num_redirects} shows the number of redirects that were followed in the request.
%{redirect_url} shows the actual URL a redirectwouldtake you to when an HTTP request was made without-Lto follow redirects.
%{remote_ip} shows the remote IP address of the most recently made connection—can be either IPv4 or IPv6.
%{remote_port} shows the remote port number of the most recently made connection.
%{size_download} shows the total number of bytes that were downloaded.
%{size_header} shows the total number of bytes of the downloaded headers.
%{size_request} shows the total number of bytes that were sent in the HTTP request.
%{size_upload} shows the total number of bytes that were uploaded.
%{speed_download} shows the average download speed that curl measured for the complete download in bytes per second.
%{speed_upload} shows the average upload speed that curl measured for the complete upload in bytes per second.
%{ssl_verify_result} shows the result of the SSL peer certificate verification that was requested. 0 means the verification was successful.
%{time_appconnect} shows the time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed.
%{time_connect} shows the time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.
%{time_namelookup} shows the time, in seconds, it took from the start until the name resolving was completed.
%{time_pretransfer} shows the time, in seconds, it took from the start until the file transfer was just about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved.
%{time_redirect} shows the time, in seconds, it took for all redirection steps including name lookup, connect, pre-transfer and transfer before the final transaction was started. time_redirect shows the complete execution time for multiple redirections.
%{time_starttransfer} shows the time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result.
%{time_total} shows the total time, in seconds, that the full operation lasted. The time will be displayed with millisecond resolution.
%{url_effective} shows the URL that was fetched last. This is particularly meaningful if you have told curl to follow Location: headers (with-L).
curl -o /dev/null -s -w %{http_code}:%{http_connect}:%{content_type}:%{time_namelookup}:%{time_redirect}:%{time_pretransfer}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} www.baidu.com
也可以放入文件:
#vim curl-time.txt
\n
http: %{http_code}\n
dns: %{time_namelookup}s\n
redirect: %{time_redirect}s\n
time_connect: %{time_connect}s\n
time_appconnect: %{time_appconnect}s\n
time_pretransfer: %{time_pretransfer}s\n
time_starttransfer: %{time_starttransfer}s\n
size_download: %{size_download}bytes\n
speed_download: %{speed_download}B/s\n
----------\n
time_total: %{time_total}s\n
\n
#curl -w "@curl_time.txt" -s -H "Content-Type: application/json" --insecure --header 'Host: passport.500.com' --data '{"platform":"android","userimei":"F5D815EA2BD8DBARD","app_channel":"10000","mbimei":"9DB358AF","version":"3.1.4","username":"hqzx","userpass":"976af4"}' --compressed https://119.147.113.177/user/login
参考:http://blog.csdn.net/hqzxsc2006/article/details/50547684
网友评论