我试图连接到一个https网站与WWW:机械。当我运行我的脚本时,我会收到错误“网络是不可访问的.”消息如下所示。
为什么它使用的是http.pm而不是该目录中的https.pm?源和错误在下面..。
#!/usr/bin/env perl
use LWP::UserAgent;
use LWP::Protocol::https;
use WWW::Mechanize;
$ENV{HTTPS_DEBUG} = 1;
print "WWW::Mechanize: ", $WWW::Mechanize::VERSION, "\n";
print "LWP : ", $LWP::UserAgent::VERSION, "\n";
print "LWP::Protocol::https : " , $LWP::Protocol::https::VERSION, "\n";
my $mech = WWW::Mechanize->new();
my $ua = LWP::UserAgent->new;
$ua->protocols_allowed(['https']);
$mech->add_handler("request_send", sub { shift->dump; return });
$mech->add_handler("response_done", sub { shift->dump; return });
my $url ="https://www.cpan.org";
$mech->get( $url );
my @links = $mech->links();
for my $link ( @links ) {
printf "%s, %s\n", $link->text, $link->url;
}输出:
WWW::Mechanize: 1.75
LWP : 6.13
LWP::Protocol::https : 6.06
GET https://www.cpan.org
Accept-Encoding: gzip
User-Agent: WWW-Mechanize/1.75
(no content)
500 Can't connect to www.cpan.org:443
Content-Type: text/plain
Client-Date: Fri, 06 Nov 2015 03:29:49 GMT
Client-Warning: Internal response
Can't connect to www.cpan.org:443\n
Network is unreachable at /home/coldsoda/localperl/lib/site_perl/5.22.0/LWP/Protocol/http.pm line 47.\n
Error GETing https://www.cpan.org: Can't connect to www.cpan.org:443 at ./mechurl.pl line 24.发布于 2015-11-06 05:53:09
我的$url ="https://www.cpan.org";
当脚本到达站点时遇到问题时,规则#1 :与浏览器检查。意外:它在使用ERR_CONNECTION_REFUSED的浏览器中失败。这就告诉您,浏览器也无法访问站点,那么为什么它应该与脚本一起工作呢?
为什么它使用的是http.pm而不是该目录中的https.pm?
因为https只是一个SSL隧道中的http,所以LWP中的https支持大量使用了http支持。因此,您可以从http.pm获得错误消息。
https://stackoverflow.com/questions/33559009
复制相似问题