in reply to Re^3: Error 500 in LWP
in thread Error 500 in LWP

With the local network all right, the command is executed and save file. But script LWP with error, there dump:
# perl ssl.pl $VAR1 = bless( { '_content' => '500 Can\'t connect to www.microsoft.c +om:443 (connect: Network is unreachable) ', '_rc' => 500, '_headers' => bless( { 'client-warning' => 'Internal + response', 'client-date' => 'Fri, 18 Aug + 2017 08:51:50 GMT', 'content-type' => 'text/plain +' }, 'HTTP::Headers' ), '_msg' => 'Can\'t connect to www.microsoft.com:443 ( +connect: Network is unreachable)', '_request' => bless( { '_content' => '', '_uri' => bless( do{\(my $o = + 'https://www.microsoft.com/uk-ua/')}, 'URI::https' ), '_headers' => bless( { 'user-agent' => 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit +/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36' }, 'HTTP +::Headers' ), '_method' => 'GET' }, 'HTTP::Request' ) }, 'HTTP::Response' );

Replies are listed 'Best First'.
Re^5: Error 500 in LWP
by hippo (Archbishop) on Aug 18, 2017 at 10:11 UTC
    https://www.microsoft.com/uk-ua/

    So, I see you have changed the target URL again. I wonder why. Anyway, here, on CentOS 6 is the script which works absolutely perfectly for me:

    use strict; use warnings; use Test::More tests => 1; use LWP::UserAgent; use Data::Dumper; my $ua = LWP::UserAgent->new; my $res = $ua->get ('https://www.microsoft.com/uk-ua/'); is ($res->code, 200, 'Download succeeded'); diag (qq# LWP: $LWP::VERSION IO::Socket::SSL: $IO::Socket::SSL::VERSION#);

    Which gives:

    $ perl sslms.pl 1..1 ok 1 - Download succeeded # # LWP: 5.833 # IO::Socket::SSL: 1.31
      Yes, I changed a little, because I'm looking for a working code.

      Here is a new code where Google returns a different code.

      use strict; use warnings; use LWP::UserAgent; my @hostnames = ( 'http://google.com', 'https://google.com', 'http://microsoft.com', 'https://microsoft.com', 'http://bing.com', 'https://bing.com', ); my $ua = LWP::UserAgent->new; for my $host (@hostnames) { my $res = $ua->get ($host); print $res->code . ' => ' . $res->status_line . "\n"; } print "LWP: $LWP::VERSION\n"; print "IO::Socket::SSL: $IO::Socket::SSL::VERSION\n";
      It returns:
      200 => 200 OK 500 => 500 Can't connect to google.com:443 (connect: Network is unreac +hable) 500 => 500 Can't connect to www.microsoft.com:443 (connect: Network is + unreachable) 500 => 500 Can't connect to www.microsoft.com:443 (connect: Network is + unreachable) 200 => 200 OK 200 => 200 OK LWP: 5.833 IO::Socket::SSL: 1.31

        Well, donning my deerstalker and poring through these extra datapoints I see a pattern emerging. Your client is unable to connect to a URL when using both HTTPS and IPv6. google.com and www.microsoft.com both have IPv6 addresses but bing.com does not (bad bing!). Only you can test this further by adding more data to the set.

        You could try to "fix" this by pre-loading IO::Socket::SSL with the appropriately restrictive option:

        use IO::Socket::SSL 'inet4'; use LWP::UserAgent;

        ... but the real fix is to talk to your systems administrator and have them sort out the problem with your IPv6 connectivity.