我有一个用于从 Google 获取内容的脚本。它工作得很好,但现在不行了。我在 stackexchange 上找到了一个帖子,我升级了库版本,但它仍然不起作用:I cannot Connect to any HTTPS site using LWP::UserAgent
我有来自 linux 机器的连接(telnet googleapis.com 443 工作得很好)。
#!/usr/bin/perl
use CGI 'param';
use CGI::Carp 'fatalsToBrowser';
use DBI;
require LWP::UserAgent;
use LWP::Protocol::https;
use URI::Escape;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
$access_token='xxx';
print "LWP::UserAgent: ".LWP::UserAgent->VERSION,"\n";
print "LWP::Protocol::https: ".LWP::Protocol::https->VERSION,"\n";
$url="https://www.googleapis.com/oauth2/v1/userinfo?access_token=$access_token";
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
$ua->agent('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36');
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get("$url");
if ($response->is_success) {
print "Am adus cu succes contul de la google";
$text=$response->decoded_content; # or whatever
}
else {
print "Response error:".$response->status_line."\n";
}
1;
错误:500 无法连接到 www.googleapis.com:443
知道为什么会突然发生这种情况吗?
最佳答案
您需要使用 CPAN 或通过包名 perl-LWP-Protocol-https
安装 LWP::Protocol::https
。
对我有用的是,在 CentOS 上以 root 身份运行,按包名安装它
yum install perl-LWP-Protocol-https
After that https links are opened as they should, with out an empty response.
关于Perl LWP::UserAgent 无法连接到 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27169592/