我正在尝试访问 HTTPS 网站,但出现错误。我试过这个脚本:
脚本 1:
use strict;
use warnings;
use LWP::UserAgent;
my $B = new LWP::UserAgent (agent => 'Mozilla/5.0', cookie_jar =>{});
my $GET = $B->get('https://moz.com')->content;
print $GET;
脚本 2:
use strict;
use warnings;
use LWP::UserAgent;
use Mozilla::CA;
my $B = new LWP::UserAgent (agent => 'Mozilla/5.0', cookie_jar =>{});
$B->ssl_opts( SSL_ca_file => Mozilla::CA::SSL_ca_file() );
$B->ssl_opts( verify_hostname => 1 );
my $GET = $B->get('https://moz.com')->content;
print $GET;
我在这两个方面都遇到了这个错误:
Can't connect to moz.com:443
LWP::Protocol::https::Socket: SSL connect attempt failed with unknown error error:00000000:lib(0):func(0):reason(0) at C:/Perl/site/lib/LWP/Protocol/http.pm line 47.
我在 Windows 7 Ultimate 上使用 ActivePerl 5.16.1 Build 1601。
知道如何使用 Perl 访问 HTTPS 网站吗?
最佳答案
如果您没有安装 LWP::Protocol::https 模块,https 调用将失败。
关于Perl - 如何请求 HTTPS 网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41860689/