perl – HTTPS代理和LWP :: UserAgent

前端之家收集整理的这篇文章主要介绍了perl – HTTPS代理和LWP :: UserAgent前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经阅读了很多网站上的一些帖子,但仍然无法完成这项工作.

我有一台运行perl 5.12.4的OpenSSL 0.9.8r的客户端机器(OSX),LWP 6.0.4,更新的Crypt :: SSLeay,Net :: SSL等.我正在尝试连接到HTTPS站点(https://github.com在例子)通过我在Windows VM上运行的WinGate代理.请注意,我的实际应用程序附加到我无法控制的SSL Web服务.

从Firefox,指向代理一切都是copacetic.页面加载成功,我在代理软件活动监视器中看到连接.如果我能在Perl中工作,我会很高兴.我已经从这个Stack Overflow问题的代码开始:How do I force LWP to use Crypt::SSLeay for HTTPS requests?添加了一些调试和额外的输出.我现在站在这里:

#!/usr/bin/perl

use strict;
use warnings;
use Net::SSL (); # From Crypt-SSLeay

BEGIN {
  $Net::HTTPS::HTTPS_SSL_SOCKET_CLASS = "Net::SSL"; # Force use of Net::SSL
  $ENV{HTTPS_PROXY} = 'https://192.168.1.11:80';
#  $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
  $ENV{HTTPS_DEBUG} = 1;  #Add debug output
}

use LWP::UserAgent;
my $ua = LWP::UserAgent->new();
my $req = HTTP::Request->new('GET','https://github.com/');
my $response = $ua->request($req);

print "--\n";
print "$_\n" for grep { $_ =~ /SSL/ } keys %INC;
print "--\n";

if ($response->is_success) {
     print $response->decoded_content;  # or whatever
     exit(0);
}
else {
 print "\nFail:\n";
     print $response->status_line ."\n";
     exit(1);
}

这是此代码输出

--
Crypt/SSLeay.pm
Crypt/SSLeay/X509.pm
Net/SSL.pm
--

Fail:
500 Can't connect to github.com:443 (Crypt-SSLeay can't verify hostnames)

如果我然后取消注释$ENV {PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;,我确实在代理上看到一个连接到github.com:443,然后什么都没有. (注意,从Web浏览器到代理,它的效果很好).经过多次挂起后,我从脚本中获得以下输出

SSL_connect:before/connect initialization
SSL_connect:SSLv2/v3 write client hello A
SSL_connect:before/connect initialization
SSL_connect:SSLv3 write client hello A
SSL_connect:Failed in SSLv3 read server hello A
SSL_connect:before/connect initialization
SSL_connect:SSLv2 write client hello A
SSL_connect:Failed in SSLv2 read server hello A
--
Crypt/SSLeay.pm
Crypt/SSLeay/X509.pm
Net/SSL.pm
Crypt/SSLeay/CTX.pm
Crypt/SSLeay/MainContext.pm
--

Fail:
500 SSL negotiation Failed:

如果有人能在这里提供一些方向,我将非常感谢!

解决方法

我刚刚将 LWP::Protocol::connect模块上传到CPAN.
此模块将缺少的HTTP / CONNECT方法支持添加到LWP.
use LWP::UserAgent;

  $ua = LWP::UserAgent->new(); 
  $ua->proxy('https','connect://proxyhost.domain:3128/');

  $ua->get('https://www.somesslsite.com');

使用此模块,您可以使用常规IO :: Socket :: SSL实现LWP> = 6.00.

原文链接:https://www.f2er.com/Perl/172871.html

猜你在找的Perl相关文章