`
bluerose
  • 浏览: 145982 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

perl动态监测文件并模拟http post提交

    博客分类:
  • Perl
阅读更多

perl中有种格式叫散列。因为我的文件名和文件路径是动态生成的。所以需要用散列。用字符串变量是不行的。

首先我检测我某个目录下面的所有文件。然后放到散列里面去。

my $dir = "C:/SmartPrinter";


opendir DH, $dir or die "Cannot open $dir: $!";
my $i=0;
my %fruit;#散列
foreach $file (readdir DH) {
    $i++;
  if($file=~/\.tif$/g){
     my $needfile = $dir."/".$file;#组装文件绝对路径
      $fruit{"faxfile$i"} = ["$needfile"];
  }
 
   }
closedir DH;

 然后模拟http post提交。提交的文件内容直接把散列变量放上去就可以了。

print %fruit ;
my $url = "http://localhost:8086/shortWave/telegraph/telegraphFax.htm?do=getFaxTelegraph";
my $ua  = LWP::UserAgent->new();
$ua->timeout(30);#超时。单位 秒
my $req = POST $url,Content_Type=>'form-data',
 Content => [
  submit=>1,
  %fruit,#这里就是所有提交的文件。
  status=>1
 ];
my $response = $ua->request($req);

if ($response->is_success()) {
    print "success";
    exit;
} else {
    print "fail";
    exit;
}

 这个问题测试了好些时间。之前一直用字符串变量是不行的。记得用散列。

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics