如何在Perl中发送URL请求
我想在一个特定的URL上发送一个XML请求,并从那里获得响应。我如何通过创建一个模块来实现这一点是Perl。我是Perl新手,请帮助我。你可以试试这个如何在Perl中发送URL请求,perl,Perl,我想在一个特定的URL上发送一个XML请求,并从那里获得响应。我如何通过创建一个模块来实现这一点是Perl。我是Perl新手,请帮助我。你可以试试这个 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,
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;
你到底想做什么?我想在url上发送xml并得到响应。类似于web服务