【问题标题】:Perl WWW:Mechanize not connecting over httpsPerl WWW:Mechanize 不通过 h​​ttps 连接
【发布时间】:2015-11-06 03:34:19
【问题描述】:

我正在尝试使用 WWW:Mechanize 连接到 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.

【问题讨论】:

  • 我无法通过浏览器使用https 连接到https://www.cpan.org,但可以使用您的脚本连接到https://metacpan.org/。我猜 CPAN 不支持https

标签: perl https mechanize www-mechanize


【解决方案1】:

我的 $url ="https://www.cpan.org";

当脚本到达站点时遇到问题时规则 #1:检查浏览器。惊喜:它在浏览器中以 ERR_CONNECTION_REFUSED 失败。这告诉您该网站也无法在浏览器中使用,那么为什么要使用该脚本。

为什么它使用 http.pm 而不是该目录中存在的 https.pm?

因为 https 只是 SSL 隧道中的 http LWP 中的 https 支持大量使用了 http 支持。因此,您会从 http.pm 收到错误消息。

【讨论】:

  • 谢谢。我尝试了多个站点来测试 http v https,而 http.pm 问题的存在使我的思维蒙上了阴影。
猜你喜欢
  • 2020-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-25
  • 2011-06-15
  • 2015-12-04
  • 2021-09-07
  • 2016-05-21
相关资源
最近更新 更多