2013-10-09 71 views

回答

2

使用此

use LWP::UserAgent; 

my $ua = LWP::UserAgent->new; 

my $server_endpoint = ""; 

# set custom HTTP request header fields 
my $req = HTTP::Request->new(GET => $server_endpoint); 
$req->header('content-type' => 'application/json'); 


my $resp = $ua->request($req); 
if ($resp->is_success) { 
    my $message = $resp->decoded_content; 
    print "Received reply: $message\n"; 
} 
else { 
    print "HTTP GET error code: ", $resp->code, "\n"; 
    print "HTTP GET error message: ", $resp->message, "\n"; 
} 

或者你也可以做到這一點的方法也使用LWP::Simple

use strict; 
use warnings; 
use LWP::Simple; 

my $url = 'http://www.example.com'; 
my $content = get $url or die "Unable to get $url\n"; 
print $content; 
+0

很難用LWP :: Simple做一個POST。 –