How to force LWP to use Crypt :: SSLeay for HTTPS requests?

My symptom is that I cannot use a proxy server with HTTPS requests with LWP. This is apparently a common problem, and the hints on Google and even here all offer a workaround to set the HTTPS_PROXY environment HTTPS_PROXY to use Crypt :: SSLeay.

My specific problem is that LWP :: Protocol :: https loads IO :: Socket :: SSL, not Crypt :: SSLeay. How can I force Crypt :: SSLeay?

My code is:

 #!/usr/bin/perl use strict; use warnings; $ENV{HTTPS_PROXY} = 'http://10.0.3.1:3128'; use LWP::UserAgent; my $ua = LWP::UserAgent->new(); my $req = HTTP::Request->new('GET','https://www.meritrustcu.org/'); my $res = $ua->request($req); print "$_\n" for grep { $_ =~ /SSL/ } keys %INC; 

And it outputs, showing that Crypt :: SSLeay is not used:

 Net/SSLeay.pm IO/Socket/SSL.pm /usr/lib/perl5/auto/Net/SSLeay/autosplit.ix /usr/lib/perl5/auto/Net/SSLeay/set_proxy.al /usr/lib/perl5/auto/Net/SSLeay/randomize.al 

Just adding explicit use Crypt::SSLeay to my script turned out to be ineffective. It loads the module, but it continues to load IO :: Socket :: SSL and use it for HTTPS requests.

+7
source share
2 answers

Try the following:

 use strict; use warnings; use Net::SSL (); # From Crypt-SSLeay BEGIN { $Net::HTTPS::SSL_SOCKET_CLASS = "Net::SSL"; # Force use of Net::SSL $ENV{HTTPS_PROXY} = 'http://10.0.3.1:3128'; } use LWP::UserAgent; my $ua = LWP::UserAgent->new(); my $req = HTTP::Request->new('GET','https://www.meritrustcu.org/'); my $res = $ua->request($req); print "$_\n" for grep { $_ =~ /SSL/ } keys %INC; 

I do not have a suitable proxy, so I have not tried it myself.

+9
source

This is what I did so that LWP and SOAP :: Lite work with our proxy server in GE. This happened after multiple copying to CPAN, google, etc. I finally realized this after running the test script in the Crypt :: SSLeay package called net_ssl_test, and it was able to connect through a proxy. The key forces Crypt :: SSLeay to use Net :: SSL, as mentioned above. However, this is not well documented on CPAN.

 use LWP::UserAgent; # override HTTPS setting in LWP to work with a proxy $ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "Net::SSL"; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; $ENV{HTTPS_PROXY} = 'http-proxy.ae.ge.com:80'; $ENV{HTTPS_PROXY_USERNAME} = 'username'; $ENV{HTTPS_PROXY_PASSWORD} = 'password'; $ua = new LWP::UserAgent; # make a https request my $req = HTTP::Request->new(GET => 'https://mail.google.com/'); my $res = $ua->request($req); print $res->as_string; 
+1
source

All Articles