Perl LWP::UserAgent 无法连接到 HTTPS

标签 perl ssl https google-api lwp-useragent

我有一个用于从 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/

相关文章:

perl - 将数据结构转化为perl对象(模块推荐)

html - 如何使用 Perl 提取并格式化 div 标签中的 HTML?

php - 强制 https 时在 symfony2 中重定向循环

c# - 为 c# Post 使用不受信任的 ssl 证书

ssl - 如何调试 https 设置?

perl - 我应该在编译时而不是运行时建立继承,如果是,为什么?

python pdb 相当于可调用的 perldb 方法?

c# - SSL/TLS WCF 问题

ssl - curl: (7) 无法连接到 xx.xx.xx.xx:80;连接被拒绝

google-chrome - 当你使用 'badidea' 或 'thisisunsafe' 绕过 Chrome 证书/HSTS 错误时,它只适用于当前站点吗?