Perl LWP :: UserAgent无法连接到HTTPS

时间:2014-11-27 11:26:51

标签: 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

知道为什么会突然发生这种情况?

2 个答案:

答案 0 :(得分:2)

在某些情况下,您需要强制使用SSLv3

my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0, SSL_version => 'SSLv3' });

答案 1 :(得分:0)

您需要使用CPAN或程序包名称LWP::Protocol::https安装perl-LWP-Protocol-https

对我有用的是,通过以root身份运行在CentOS上按包名安装它yum install perl-LWP-Protocol-https

  

之后 https 链接按原样打开,没有空响应。