Perl LWP :: UserAgent无法连接到HTTPS

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

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

最佳答案 在某些情况下,您需要强制使用SSLv3

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