title: HTTPS Proxy and LWP::UserAgent
body: <p>I have read a number of threads on a number of sites and am still unable to make this work. </p>
  
  <p>I have a client machine (OSX) with OpenSSL 0.9.8r running perl 5.12.4, with LWP 6.0.4, updated Crypt::SSLeay, Net::SSL etc. I am trying to connect to an HTTPS site (<a href="https://github.com" rel="nofollow noreferrer">https://github.com</a> in the example) via a WinGate proxy that I have running on a Windows VM. Note that my actual application is attaching to an SSL webservice that I have no control over.</p>
  
  <p>From Firefox, pointed to the proxy everything is copacetic. The page loads successfully and I see the connections in the Proxy software Activity monitor. I'll be darned if I can make it work in Perl though. I've started with the code from this Stack Overflow Question : <a href="https://stackoverflow.com/questions/8026524">How do I force LWP to use Crypt::SSLeay for HTTPS requests?</a> And added some debugging and additional output. Here's were I stand now:</p>
  
  <pre class="lang-perl prettyprint-override"><code>#!/usr/bin/perl
  
  use strict;
  use warnings;
  use Net::SSL (); # From Crypt-SSLeay
  
  BEGIN {
    $Net::HTTPS::HTTPS_SSL_SOCKET_CLASS = "Net::SSL"; # Force use of Net::SSL
    $ENV{HTTPS_PROXY} = 'https://192.168.1.11:80';
  #  $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
    $ENV{HTTPS_DEBUG} = 1;  #Add debug output
  }
  
  use LWP::UserAgent;
  my $ua = LWP::UserAgent-&gt;new();
  my $req = HTTP::Request-&gt;new('GET','https://github.com/');
  my $response = $ua-&gt;request($req);
  
  print "--\n";
  print "$_\n" for grep { $_ =~ /SSL/ } keys %INC;
  print "--\n";
  
  if ($response-&gt;is_success) {
       print $response-&gt;decoded_content;  # or whatever
       exit(0);
  }
  else {
   print "\nFail:\n";
       print $response-&gt;status_line ."\n";
       exit(1);
  }
  </code></pre>
  
  <p>Here's the output from this code:</p>
  
  <pre><code>--
  Crypt/SSLeay.pm
  Crypt/SSLeay/X509.pm
  Net/SSL.pm
  --
  
  Fail:
  500 Can't connect to github.com:443 (Crypt-SSLeay can't verify hostnames)
  </code></pre>
  
  <p>If I then uncomment <code>$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;</code>, I do see a single connect to github.com:443 on the proxy and then nothing. <em>(Note it works great from a web browser through the proxy)</em>. After much hanging I get the following output from the script:</p>
  
  <pre><code>SSL_connect:before/connect initialization
  SSL_connect:SSLv2/v3 write client hello A
  SSL_connect:before/connect initialization
  SSL_connect:SSLv3 write client hello A
  SSL_connect:failed in SSLv3 read server hello A
  SSL_connect:before/connect initialization
  SSL_connect:SSLv2 write client hello A
  SSL_connect:failed in SSLv2 read server hello A
  --
  Crypt/SSLeay.pm
  Crypt/SSLeay/X509.pm
  Net/SSL.pm
  Crypt/SSLeay/CTX.pm
  Crypt/SSLeay/MainContext.pm
  --
  
  Fail:
  500 SSL negotiation failed: 
  </code></pre>
  
  <p>If anyone can provide some direction here I would greatly appreciate it!</p>