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

Hello to all! I am using LWP to get simple content (http) via local proxy, but when I get content with via https protocol I get error:  https://kuix.de/: Can't connect to kuix.de:443 (10051)

My script

use strict; use warnings; use feature qw (say switch); use LWP; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; $ENV{HTTPS_DEBUG} = 1; #my $url = 'http://google.com'; my $url = 'https://kuix.de/'; my $ua = LWP::UserAgent->new(); $ua->agent('User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18 +.0) Gecko/20100101 Firefox/18.0'); $ua->show_progress('true'); $ua->ssl_opts ( verify_hostname => '0', SSL_ca_file => 'CA.crt'); + $ua->proxy( ['http'], 'http://user:pass@host:port' ); my $req = HTTP::Request->new( 'GET' => $url ); my $res = $ua->request($req); $res->is_success or die "$url: ", $res->message, "\n"; say $res->content;

Please help me! Sorry but I am new perl user

Replies are listed 'Best First'.
Re: LWP https proxy trouble
by Corion (Patriarch) on Apr 11, 2013 at 11:46 UTC
    Can't connect to kuix.de:443 (10051)

    This means your computer cannot connect to the other computer.

    Have you checked that your browser can connect to the website? Maybe there are proxy settings that you need to tell your Perl script?

    Update: I now realize that you're already aware that you need a proxy. For SSL, you need to tell the SSL C libraries to use a proxy. The best approach is to set up the environment before these libraries are loaded. This is easiest done by setting up the environment before your Perl script is started. As an alternative, you can set up the environment in a BEGIN block before the SSL libraries are initialized:

    BEGIN { $ENV{ https_proxy } = "http://my.proxy.example"; }; ... use LWP::UserAgent;
      How about that my proxy avaliable via just a HTTP, and I am using verify_hostname => '0' or  $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
      Yes, when i get https://kuix.de from my browser with the same proxy settings all OK. When I get content of http://google.com from script all OK, but when via HTTPS (as example https://kuix.de) is not OK
Re: LWP https proxy trouble
by vsespb (Chaplain) on Apr 11, 2013 at 12:48 UTC
    For HTTPS URLs you need HTTPS proxy. And I think LWP does not support HTTPS proxy - bug since Y2002 https://rt.cpan.org/Public/Bug/Display.html?id=1894 (there are workarounds)
      Thank for link (https://rt.cpan.org/Public/Bug/Display.html?id=1894)! It is very helped me! Now all works! Thanks to all!
Re: LWP https proxy trouble
by Anonymous Monk on Jul 22, 2013 at 12:09 UTC
    I just uploaded the LWP::Protocol::connect module to CPAN. This module adds the missing HTTP/CONNECT method support to LWP.
    use LWP::UserAgent; $ua = LWP::UserAgent->new(); $ua->proxy('https', 'connect://proxyhost.domain:3128/'); $ua->get('https://www.somesslsite.com');
    With this module you can use the regular IO::Socket::SSL implementation for LWP >=6.00.
      Tried LWP::Protocol::connect to get over this problem: $userAgent->proxy('https',"connect://my-proxy:8080/"); 500 Bad arg length for Socket6::unpack_sockaddr_in6, length is 16, should be 28 Content-Type: text/plain Client-Date: Wed, 16 Oct 2013 15:46:07 GMT Client-Warning: Internal response Bad arg length for Socket6::unpack_sockaddr_in6, length is 16, should be 28 at /usr/lib/perl5/Socket6.pm line 282, <> line 1.
      (sorry about malformed comment)

      Tried LWP::Protocol::connect to get over this problem:

      $userAgent->proxy('https',"connect://my-proxy:8080/");

      500 Bad arg length for Socket6::unpack_sockaddr_in6, length is 16, sho +uld be 28 Content-Type: text/plain Client-Date: Wed, 16 Oct 2013 15:46:07 GMT Client-Warning: Internal response
      Bad arg length for Socket6::unpack_sockaddr_in6, length is 16, should be 28 at /usr/lib/perl5/Socket6.pm line 282, <> line 1.