2013-08-28 21 views
-3

我想在特定的URL上发送XML请求并从那里获取resposne。我可以通过创建A模块来做到这一点是Perl。我是Perl新手请帮忙我 。如何在Perl中的URL上发送请求

+0

ü要做些什么?exactlly – Developer

+0

我想发送一个URL的XML并得到响应。一些像Web服务 – Pankaj

回答

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; 
+0

感谢您的帮助 – Pankaj