⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generate_test

📁 ICS 课程的Lab8
💻
字号:
#!/usr/local/bin/perl -wuse strict;use LWP;use URI::URL;#### Declarationsmy $base_file = "test";my $total = "";my ($tst_file, $ans_file, $url, $method, $headerobj, @headers);my $UA = new LWP::UserAgent;#### Initialization$UA->agent("Mozilla/8.0");$base_file = $ARGV[0] if($#ARGV >= 0);$tst_file = "$base_file.tst";$ans_file = "$base_file.ans";#### Generate a test case based upon an input requestprint "Input a request:\n\n";while(<STDIN>) {  $total .= $_;  chomp;  last if($_ eq "");    if($_ =~ /(\S+):\s+(.*)/) {    push @headers, ($1 => $2);  } elsif($_ =~ /(\S+)\s+(.*)(\s+.*)?$/) {    $method = $1;    $url = $2;  } else {    die ("Invalid line");  }}die ("No URL found") if(!(defined $url));$headerobj = new HTTP::Headers(@headers);my $response = $UA->request(HTTP::Request->new($method => $url, $headerobj));if($response->is_success) {  open FILE, "> $tst_file";  print FILE $total;  close FILE;  open FILE, "> $ans_file";  print FILE $response->content();  close FILE;}else{  print "request not successful";}print "Done!\n";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -