sumeetgrover has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed monks,
I am running the following code on Linux to access https://google.co.uk via an internal proxy

#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use MIME::Base64; use Data::Dumper; my $url='https://google.co.uk'; $ENV{'HTTP_PROXY'}="http://websense:8080"; $ENV{'HTTPS_PROXY'}="http://websense:8080"; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0; $ENV{HTTP_DEBUG}=1; my $ua=LWP::UserAgent->new('env_proxy'=>1,ssl_opts=>{verify_hostname=> +0}); $ua->env_proxy(); my $result=$ua->get($url); print("\n $@");

I get the following error:

Can't connect to google.co.uk:443 (Bad hostname) LWP::Protocol::https::Socket: Bad hostname 'google.co.uk' at /usr/loca +l/perl/lib/site_perl/LWP/Protocol/http.pm line 47.

If I run this script by changing the URL to 'http', i.e. insecure URL, I get the results from google.co.uk. Whereas 'httpS' returns the above error.

I have looked at various internet forums and can't figure out how to fix this. I have also tried to fetch https://google.co.uk from 'curl' command using the proxy and that returns a result. This clearly indicates there is something in my Perl script that I need to do.

Can you help?

Replies are listed 'Best First'.
Re: LWP::UserAgent - Problem with httpS URL access via proxy
by kennethk (Abbot) on May 06, 2016 at 15:01 UTC
    The error looks a little inconsistent with the following advice, but have you successfully had any HTTPS connections? Historically, you need to install Crypt::SSLeay if you want to use LWP::UserAgent with secure connections, and I remember the error condition being unclear. Though the docs look like the necessary chunks of Crypt::SSLeay have been moved into LWP::Protocol::https.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.