当我们执行下面的GET请求时,我们注意到响应时间的差异。在第一种情况下,我们尝试使用curl和cookie。在这种情况下,响应如下:
案例1:
#!/usr/bin/perl
use JSON;
use Data::Dumper;
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
my $Starttime = time();
print "Start Time : $Starttime\n\n";
$URL = "https://NN:NN:NN:NN:443";
my $cookie = "/tmp/ViptelaCookie.txt";
my $LoginReturn = `curl -k -c$cookie -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "j_username=abc&j_password=pwd" '$URL/j_security_check'`;
# Query Alarms
my $DeviceReturn = `curl -X GET -b $cookie -k -v $URL/dataservice/alarms`;
print "Returned Hash-".Dumper($DeviceReturn);
my $Endtime = time();
print "End Time : $Endtime\n";
my $Response = $Endtime-$Starttime;
print "Output Retrieved in $Response Secs...\n\n";
案例1:
开始时间:1524230391
GET / dataservice / alarms HTTP / 1.1 User-Agent:curl / 7.19.7(x86_64-redhat-linux-gnu)libcurl / 7.19.7 NSS / 3.27.1 zlib / 1.2.3 libidn / 1.18 libssh2 / 1.4.2 主办: 接受: / Cookie:JSESSIONID = %总收到百分比%Xferd平均速度时间时间当前时间 Dload上传总剩余速度0 0 0 0 0 0 0 0 - : - : - - : - : - - : - : - 0< HTTP / 1.1 200 OK<连接:keep-alive<变化:接受编码<缓存控制:无缓存,无存储,必须重新验证< 严格运输安全:max-age = 31536000; includeSubDomains< X-Frame-Options:DENY< Content-Type:application / json< 内容长度:1460<日期:2018年4月20日星期五13:20:01 GMT< {[数据 未显示] 104 1460 104 1460 0 0 16128 0 - : - : - - : - : - - : - : - 73000 *连接#0主机保持原样
- 关闭连接#0
结束时间:1524230391输出检索为0秒...
在案例2中,我们尝试使用下面的Rest Client,在这种情况下,它需要60秒。
use REST::Client;
use MIME::Base64;
use JSON;
use Data::Dumper;
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
my $Starttime = time();
print "Start Time : $Starttime\n\n";
# Set up the connection
my $client = REST::Client->new();
$client->getUseragent()->ssl_opts( SSL_verify_mode => 0 );
$client->setHost("https://NN.NN.NN.NN:443");
# Setup the basic authorization header with the encoded Userid and Password.
$client->addHeader(Authorization => 'Basic ' . encode_base64("abc:pwd"));
# Do the HTTP GET to get the lists of devices
$client->GET("/dataservice/alarms");
print "Response Code: ". $client->responseCode(). "\n";
print "Actual Response: ". $client->responseContent(). "\n\n";
my $Endtime = time();
print "End Time : $Endtime\n";
my $Response = $Endtime-$Starttime;
print "Output Retrieved in $Response Secs...\n\n";
# Deserialize the JSON response into a hash
my $response = decode_json($client->responseContent());
开始时间:1524229832
结束时间:1524229892 输出检索60秒...
非常感谢您阅读。