" with https I'm kind of new with perl, even newer for Mechanize. So far, when I tried to ...">

Perl mechanization only responds with "<HTML> </HTML>" with https

I'm kind of new with perl, even newer for Mechanize. So far, when I tried to find the site via http, this is not a problem.

Now I need to get a site with https. I installed Crypt::SSLeay

via PPM.

When I use $mech->get($url)

, however, this is the only answer I get:

"<HTML></HTML>"

      

I checked the status and success, both were ok (200 and 1).

Here's my code:

use strict;
use warnings;
use WWW::Mechanize;
use Crypt::SSLeay;
$ENV{HTTPS_PROXY} = 'http://username:pw@host:port';
//I have the https_proxy env variable set globally too.

my $url = 'https://google.com';
//Every https site has the same response, 
//so I don't think google would cause problems.

my $mech = WWW::Mechanize->new(noproxy => 0);
$mech->get($url) or die "Couldn't load page";

print "Content:\n".$mech->response()->content()."\n\n";

      

As you can see, I am for the proxy. I tried to install

$mech->proxy($myproxy);

      

but to no avail. I even tried to extract it to a file, but when I checked it I got the same responsive content.

Any advice would be appreciated as I am just a beginner and there is a lot more to learn about everything. Thank!

+3


source to share


1 answer


I think the answer lies here: How do I force LWP to use Crypt :: SSLeay for HTTPS requests?



 use Net::SSL (); # From Crypt-SSLeay
 BEGIN {
   $Net::HTTPS::SSL_SOCKET_CLASS = "Net::SSL"; # Force use of Net::SSL
   $ENV{HTTPS_PROXY} = 'http://10.0.3.1:3128'; #your proxy!
   $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
 }

      

+1


source







All Articles