Perl WWW:机械化不通过https连接https
问题描述:
我想通过WWW连接到https网站:机械化。当我运行我的脚本时,我收到下面显示的错误“Network is unreachable ...”消息。Perl WWW:机械化不通过https连接https
为什么它使用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.
答
我的$ URL = “https://www.cpan.org”;
当脚本到达站点时遇到问题时的规则1:使用浏览器进行检查。惊喜:它在浏览器中通过ERR_CONNECTION_REFUSED失败。这告诉你,该网站也不适用于浏览器,为什么它应该与脚本一起工作。
为什么它使用http.pm而不是https.pm它存在于该目录中?
因为https只是SSL隧道内的http,因此https支持在LWP中大量使用http支持。因此你从http.pm获得错误信息。
+0
谢谢。我曾尝试多个网站来测试http v https,并且http.pm问题的存在掩盖了我的想法。 – ColdSoda
我无法通过浏览器使用“https”连接到“https:// www.cpan.org”,但可以使用脚本连接到“https:// metacpan.org /”。我猜CPAN不支持'https'。 –