http://www.perlmonks.org?node_id=922226

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

In wget, there is an option '--no-check-certificate'. Is there an equivalent of this in WWW::Mechanize?

I know Mechanize uses LWP::UserAgent, and it does have these methods.
$ua->ssl_opts $ua->ssl_opts( $key ) $ua->ssl_opts( $key => $value )
But I don't know how to get the equivalent of '--no-check-certificate'. Thanks.

Replies are listed 'Best First'.
Re: Mechanize and Bypassing SSL Certificate Check
by derby (Abbot) on Aug 25, 2011 at 00:06 UTC

    I don't think LWP::UserAgent exposes that option; however, you can set the PERL_LWP_SSL_VERIFY_HOSTNAME environment var to 0 to bypass the cert check.

    $ export PERL_LWP_SSL_VERIFY_HOSTNAME=0 $ ./my_mech_script

    -derby
Re: Mechanize and Bypassing SSL Certificate Check
by repellent (Priest) on Aug 25, 2011 at 01:39 UTC
    $ua->ssl_opts(verify_hostname => 0);

    See LWP::UserAgent and search for $ua->ssl_opts.

    Update: Gah. The OP was talking about WWW::Mechanize.

    WWW::Mechanize passes its constructor arguments up to its parent (LWP::UserAgent). Try this:
    use WWW::Mechanize; my $mech = WWW::Mechanize->new( ssl_opts => { verify_hostname => 0, }, );
      Thanks, it works. But how come this didn't work?
      $mech->ssl_opts( verify_hostname => 0 );
      I thought Mechanize inherited most of the methods from LWP::UserAgent.

      Because if I tried this which is from LWP::UserAgent, it works fine.
      $mech->timeout( 100 );
        What do you mean exactly by "this didn't work"? Can you call the method ->ssl_opts on the $mech object?

        After you use WWW::Mechanize; what is the value of $LWP::UserAgent::VERSION and $WWW::Mechanize::VERSION?
Re: Mechanize and Bypassing SSL Certificate Check
by Anonymous Monk on Aug 26, 2011 at 17:27 UTC
    Here's my script:
    #!/usr/bin/perl use strict; use WWW::Mechanize; my $url = 'http://www.google.com'; my $m = WWW::Mechanize->new(); print "LWP: $LWP::UserAgent::VERSION\n"; print "Mech: $WWW::Mechanize::VERSION\n"; $m->ssl_opts( verify_hostname => 0 );
    Here's the output:
    LWP: 5.835 Mech: 1.56 Can't locate object method "ssl_opts" via package "WWW::Mechanize" at +90.pl line 11.