Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 用Perl发送rest请求_Linux_Perl_Shell - Fatal编程技术网

Linux 用Perl发送rest请求

Linux 用Perl发送rest请求,linux,perl,shell,Linux,Perl,Shell,是否可以发送rest请求,包括perl/shell脚本/命令行中的头身份验证。并获得响应?如果您想在Perl中操纵结果,可以这样做: use strict; use warnings; use LWP::UserAgent; my $ua=LWP::UserAgent->new; my $result=$ua->get("http://www.google.com/"); print $result->content; 或者,对于基本的HTTP身份验证,如下所示: us

是否可以发送rest请求,包括perl/shell脚本/命令行中的头身份验证。并获得响应?

如果您想在Perl中操纵结果,可以这样做:

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

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

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

print $result->content;
或者,对于基本的HTTP身份验证,如下所示:

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;

有关密码的来源,请参阅。这是我找到的第一个需要基本身份验证的随机页面。

这段代码没有显示它,但是是的,您也可以设置请求头和内容。参见perldoc:这非常好用+1,我使用了default_头而不是凭据,我对perl非常熟悉。您能告诉我或者告诉我关于这个的正确资源吗:我如何检查响应是否是xml,以及响应代码是否是200?谢谢您想要阅读LWP文档:并在这里特别查看响应类:挑剔。您不发送“休息请求”。您可以发送HTTP请求。如果您不介意使用一些CPAN库,这里有很好的教程