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

Hi Monks, I'm trying to do a GET request with the following code:
my $mech = LWP::UserAgent->new(ssl_opts => { SSL_key_file => $key_path, SSL_passwd_cb => sub { return $pass; }, SSL_ca_file => $ca_path, SSL_cert_file => $crt_path, verify_hostname => 1, SSL_version => 'TLSv1' }); my $content = $mech->get($url); print Dumper($content);
But it fails. $content contains: (I replaced the url with <url> for readability)
$VAR1 = bless( { '_content' => 'Can\'t connect to <url>', '_rc' => 500, '_headers' => bless( { 'client-warning' => 'Internal +response', 'client-date' => 'Thu, 01 Aug +2019 09:57:43 GMT', 'content-type' => 'text/plain' }, 'HTTP::Headers' ), '_msg' => 'Can\'t connect to <url>', '_request' => bless( { '_content' => '', '_uri' => bless( do{\(my $o = +'<url>')}, 'URI::https' ), '_headers' => bless( { 'user-a +gent' => 'libwww-perl/6.04' }, 'HTTP: +:Headers' ), '_method' => 'GET' }, 'HTTP::Request' ) }, 'HTTP::Response' );
Versions of modules:
WWW::Mechanize: 1.71 LWP : 6.04
I also unset HTTP_PROXY and HTTPS_PROXY before running the script (The code contains a check for that).
I tried to search for the solution and found a lot of posts about it but small amount of answers (that didn't help).
Similar tool which is written in JS uses those same options and succeed in getting from the url.
Btw, I can connect to the url through chrome/mozila.
What could be the issue? Maybe I should some other module which supports SSL?
Thanks for all the help!

Replies are listed 'Best First'.
Re: Performing a GET request with SSL
by 1nickt (Canon) on Aug 01, 2019 at 12:55 UTC

    Hi there again,

    Here are a few thoughts:

    • I would avoid calling your client $mech if you are not using Mechanize! $ua is a common name.

    • I would avoid calling your response object $content since it may not even have any content. $resp is a common name.

    • I would use curl -v to see more details about the request and response, or maybe even better install LWP::ConsoleLogger::Easy. I might also use $resp->as_string for a quick and dirty look at the request and response.

    • I would try to get information from the server about the internal error. Was it caused by your SSL opts? Can the admins tell you anything?

    • I would consider that the doc for LWP::UserAgent appears to show that ssl_opts only supports three of the six options you are passing it.

    Hope this helps!


    The way forward always starts with a minimal test.
Re: Performing a GET request with SSL
by daxim (Curate) on Aug 01, 2019 at 12:41 UTC
Re: Performing a GET request with SSL
by TieUpYourCamel (Scribe) on Aug 01, 2019 at 13:21 UTC
    Have you tried WWW::Mechanize?

    Have you tried connecting to a different server? Maybe this one doesn't support TLS 1.0.

Re: Performing a GET request with SSL
by bliako (Abbot) on Aug 01, 2019 at 20:35 UTC

    I noticed you get response code 500 which is Server Internal Error which means you crashed the server ;) or the server does not bother to answer to your request. However, the reported _msg is "Can\'t connect to <url>" ?

      Internal response is response from LWP -- should have said Internal LWP response, rt://LWP that