通过perl脚本调用url接口获取数据,可进行远程数据访问,相当方便:
#!/usr/bin/perl#if error for simple please command 'cpan LWP::Simple' in shell
use strict;
use warnings;
use LWP::UserAgent;
use LWP::Simple;
use utf8;
use Encode;
binmode(STDIN,':encoding(GB2312)'); binmode(STDOUT,':encoding(GB2312)'); binmode(STDERR,':encoding(GB2312)'); my $arg0 = $ARGV[0]; my $arg1 = $ARGV[1]; my $url = "http://ip/index.htm?blah=$arg0&gaga=$arg1"; my $ua = LWP::UserAgent-> new( env_proxy => 1,keep_alive => 1,timeout => 5 ); my $response = $ua-> get($url); if ($response-> is_success) { my $data = $response-> content(); print("the data is $data\n"); } else { print("can not get the data\n"); }