Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Mechanize and Bypassing SSL Certificate Check

by Anonymous Monk
on Aug 24, 2011 at 23:28 UTC ( #922226=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://922226]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2021-05-11 04:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (113 votes). Check out past polls.

    Notices?