2013-08-28 19 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