1
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use XML::Twig;
use HTTP::Request;

my @joblist = ('Testing','Integrity','TEST','Team_test','test','TEST_1','Update_Outlook');
my @score;

foreach my $job_name (@joblist) {
    my $url_a = 'http://myhost:8080/job/$job_name/api/xml';
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    $ua->env_proxy;
    my $response = $ua->get($url_a);
    if ($response->is_success) {
        my $content = $response->decoded_content;  # or whatever
        XML::Twig->new( twig_roots => { 'healthReport/score' => sub { push @score, $_->text; } }) ->parseurl($url_a);
        foreach my $var (@score) {
            print "$var \n";
        }
    }
    else {
        die $response->status_line;
    }
}

上記の perl コードでは、$job_name を別の変数 $url_a に呼び出しています。しかし、次のエラーが発生します。

404 Not Found at health.pl line 25.

誰かがこれについて私を助けてくれませんか.Thanks.

4

1 に答える 1

1

このバージョンを試してください:

#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use XML::Twig;
use HTTP::Request;

my @joblist = qw|Testing Integrity TEST Team_test test TEST_1 Update_Outlook|;
my @score;

foreach my $job_name (@joblist) {
    my $url_a = join("/","http://myhost:8080/job",$job_name,"api/xml");
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    $ua->env_proxy;
    my $response = $ua->get($url_a);
    if ($response->is_success) {
        my $content = $response->decoded_content;  # or whatever
        XML::Twig->new( twig_roots => { 'healthReport/score' => sub { push @score, $_->text; } }) ->parseurl($url_a);
        foreach my $var (@score) {
            print "$var \n";
        }
    }
    else {
        printf STDERR "ERROR job: %s, result: %s\n", 
        $job_name, $response->status_line;
    }
}
于 2012-12-28T10:04:41.247 に答える