简体   繁体   English

LWP拒绝通过HTTPS连接

[英]LWP refuses to connect via HTTPS

I am running the following Perl snippet on Debian using Perl v5.14.2 and libwww-perl v6.04-1 我使用Perl v5.14.2和libwww-perl v6.04-1在Debian上运行以下Perl代码片段

my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new("GET", "https://google.com/");
my $rep = $ua->request($req);
print $rep->status_line;

This instantly returns "500 Can't connect to google.com:443" . 这会立即返回“500无法连接到google.com:443” I have tried using LWP::Simple, Net::SSLeay, Crypt::SSLeay , etc. without any success. 我尝试过使用LWP::Simple, Net::SSLeay, Crypt::SSLeay等,没有任何成功。

Oddly enough, executing the same code on another Debian system running exactly the same Perl and LWP versions works. 奇怪的是,在运行完全相同的Perl和LWP版本的另一个Debian系统上执行相同的代码。

So I thought, there is some error with the underlying system, but other applications - like cURL for any browser - are working fine. 所以我想,底层系统有一些错误,但其他应用程序 - 比如任何浏览器的cURL - 都运行正常。

Also, openssl s_client -connect google.com:443 returns Verify return code: 20 (unable to get local issuer certificate) on both systems. 此外, openssl s_client -connect google.com:443 Verify return code: 20 (unable to get local issuer certificate)两个系统上返回Verify return code: 20 (unable to get local issuer certificate)

Has anyone ever encountered this phenomenon and has a solution? 有没有人遇到过这种现象并有解决方案?

Instead of this: 而不是这个:

$ua = LWP::UserAgent->new;

Try to use this: 试着用这个:

$ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });

FYI for others battling LWP 500 erors: 其他人与其他人争夺LWP 500的错误:

Some LWP 500 errors are apparently caused by another type of SSL problem (which isn't solved with the verify_hostname setting). 一些LWP 500错误显然是由另一种类型的SSL问题引起的(使用verify_hostname设置无法解决)。 Instead, LWP may be communicating with the HTTPS server, but the response is not what LWP expects. 相反,LWP可能正在与HTTPS服务器通信,但响应不是LWP所期望的。 In my case, the solution was to force SSLv3, by the following means: 就我而言,解决方案是通过以下方式强制使用SSLv3:

my %ssl_options = (SSL_version => 'SSLv3');
$ua = LWP::UserAgent->new(ssl_opts => \%ssl_options), 

Also, for anyone trying to figure out what kind of 500 error you are getting, output this along with your error: 此外,对于任何试图弄清楚你得到什么样的500错误的人,输出这个以及你的错误:

print $response->as_string;

For my problem (solved by setting SSLv3), my $response->as_string output included: 对于我的问题(通过设置SSLv3解决),我的$ response-> as_string输出包括:

"SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert unexpected message LWP" “SSL例程:SSL23_GET_SERVER_HELLO:sslv3警告意外消息LWP”

I'll also say that my code ran fine for years on an earlier version of Ubuntu. 我还要说我的代码在早期版本的Ubuntu上运行了很多年。 This problem only appeared once I upgraded Ubuntu. 这个问题只出现在我升级Ubuntu之后。 I've concluded that there are probably multiple ways that newer versions of LWP differ from older ones, so developers beware! 我的结论是,LWP的新版本可能有多种方式与旧版本不同,所以开发人员要小心!

Good luck solving your LWP problem! 祝你好运解决你的LWP问题!

I had this issue on Windows Server 2003 with Strawberry Perl . 我在带有Strawberry Perl的 Windows Server 2003上遇到了这个问题。 The error 500 was a problem with IO::Socket::IP . 错误500是IO::Socket::IP

Performing a re-install of the module (in cpan , force install IO::Socket::IP ) resolved the issue. 执行模块的重新安装(在cpan ,强制安装IO::Socket::IP )解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM