簡體   English   中英

Perl WWW:機械化未通過https連接

[英]Perl WWW:Mechanize not connecting over https

我正在嘗試使用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.

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

腳本到達站點時遇到問題時的規則1:使用瀏覽器檢查。 驚喜:它在瀏覽器中顯示ERR_CONNECTION_REFUSED失敗。 這告訴您該網站也無法通過瀏覽器訪問,因此為什么要與腳本一起使用。

為什么使用該目錄中的http.pm而不使用https.pm?

因為https只是SSL隧道內的http,所以LWP中的https支持大量使用了http支持。 因此,您會從http.pm獲得錯誤消息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM