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

Hi, my code is as follows
#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; use Crypt::SSLeay; # proxy $ENV{HTTPS_PROXY}='http://proxy:8080/'; my $mechanize = WWW::Mechanize->new(noproxy => 0); $mechanize->cookie_jar(HTTP::Cookies->new(file=>"mechcookies.txt",auto +save => 1)); $mechanize->proxy(['http', 'https'], 'http://proxy:8080/'); $mechanize->credentials('http://www.site.com/dashboard','ABCDEF','logi +n', 'pass'); $mechanize->get('http://www.site.com/dashboard'); #my $result = $mechanize->submit_form(form_id => 'signin',fields => { +login => 'login', password => 'pass'}); #print "$result" $mechanize->save_content('dump.html');
the problem is that it fails with retrieving https pages. I've tried adding the HTTPS_PROXY env, added noproxy => 0, I've tried going to a protected page by sending my credentials and it redirects to the home page. I'm lost. What do i do?

Replies are listed 'Best First'.
Re: www::mechanize behind proxy and https not working
by Khen1950fx (Canon) on Sep 15, 2010 at 10:47 UTC
    Since you listed Crypt::SSLeay, you want to turn off your proxy. I played with this for a while with good results. I used my credentials for PAUSE, but you can use any https site. Give it a try.
    #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; use Crypt::SSLeay; $ENV{NO_PROXY}='*'; my $mechanize = WWW::Mechanize->new( noproxy => 0, stack_depth => 5, autocheck => 1 ); $mechanize->cookie_jar( HTTP::Cookies->new( file => "mechcookies.txt", autosave => 1 ) ); $mechanize->proxy( [ 'http', 'https' ] ); $mechanize->get_basic_credentials( 'https://pause.perl.org', 'abc', '1234567' ); $mechanize->get('https://pause.perl.org'); print $mechanize->status(), "\n", $mechanize->content_type(), "\n", $mechanize->base(), "\n", $mechanize->is_html(), "\n"; $mechanize->content( format => 'text' ); $mechanize->save_content('text.html');
      Maybe there is a reason he wants to use proxy?
      It works upto 'get'.The get command gives a bad request
Re: www::mechanize behind proxy and https not working
by Anonymous Monk on Sep 15, 2010 at 06:15 UTC
    What https pages? http://www.example.com/dashboard is http not https

    FWIW, always use example.com as the example url, its the official domain reserved for this

      the dashboard page is the second attempt, by trying to send crdentials to a login protected page. Otherwise I used https
        Wait, how does it fail?
Re: www::mechanize behind proxy and https not working
by rowdog (Curate) on Sep 15, 2010 at 20:36 UTC

    Not all HTTP proxies support SSL. You might want to double check that yours does. If, for some reason, you can't read the fine manual, you can probably configure your browser to use that proxy for SSL and see if it works there.

      SSL works with the browser. I've verified it