开发者

Send rest request with Perl

Is it possible to send rest request, including header authentication in perl/shell scr开发者_JAVA技巧ipt/command line. And get the response?


Something like this if you want to manipulate the result in Perl:

use strict;
use warnings;
use LWP::UserAgent;

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

my $result=$ua->get("http://www.google.com/");

print $result->content;

Or, with basic HTTP authentication something like this:

use strict;
use warnings;
use LWP::UserAgent;

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

$ua->credentials("www.pagetutor.com:80","My Secret Area","jimmy","page");

my $result=$ua->get("http://www.pagetutor.com/keeper/mystash/secretstuff.html");

print $result->content;

See http://www.pagetutor.com/keeper/http_authentication/index.html for where the password came from. Just the first random page I found which requires basic authentication.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜