generate_test
来自「ICS 课程的Lab8」· 代码 · 共 58 行
TXT
58 行
#!/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 + =
减小字号Ctrl + -
显示快捷键?