我想在特定 URL 上发送 XML 请求并从那里获取响应。我如何通过创建模块来做到这一点是 Perl。我是 Perl 的新手请帮助我。
问问题
208 次
1 回答
0
你可以试试这个
package TEST::Http;
use strict;
use warnings;
use HTTP::Request;
use LWP::UserAgent;
use HTTP::Headers;
sub new {
my $class = shift;
my $this = {};
bless $this, $class;
return $this;
}
sub send_receive {
my $this = shift;
my $args = shift;
$this->{pua} = LWP::UserAgent->new();
$this->{header} = HTTP::Headers->new;
$this->{header}->header("Content-Type" => "text/xml", "SOAPAction" =>"");
my ($request, $response);
my $Response = {};
eval {
local $SIG{ALRM} = sub {die "Timed out"};
alarm 90;
$request = HTTP::Request->new( "POST", $args->{URL} , $args->{xml_request});
$response = $this->{pua}->simple_request($request);
alarm 0;
};
return $response->content;
}
sub DESTROY {
my $this = shift || return;
}
1;
于 2013-08-28T11:42:31.663 回答