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

Hello everyone, I'm new to perl, just a question for you experts.
I'm trying to automate a procedure that connects to a https login page through a proxy server in my company.
Follow the code I produced:
#!/usr/bin/perl use strict; use WWW::Mechanize; use HTTP::Cookies; use HTTP::Request; print " WWW::Mechanize $WWW::Mechanize::VERSION LWP $LWP::VERSION "; my $webpage = ''; my $outfile = "out.htm"; my $url = "https://xxxxx.it"; my $username = "xxxxxx"; my $password = "xxxxxx"; my $mech = WWW::Mechanize->new(); my $cookie_jar = HTTP::Cookies->new( autosave => 1, file => "cookies.t +xt"); $mech->env_proxy(); $mech->get($url); $mech->cookie_jar($cookie_jar); $mech->form_name('Login'); $mech->field(IDToken1 => $username); $mech->field(IDToken2 => $password); $mech->click(); #$mech->submit(); my $output_page = $mech->content(); open(OUTFILE, ">$outfile"); print OUTFILE "$output_page"; close(OUTFILE); print $cookie_jar->as_string, "\n";
without the proxy this seems to be working but if i try using the proxy server it doesn't work giving me back the following exit code:
400 Bad Request
Any ideas ?
Many thanks in advance.
chew23

Replies are listed 'Best First'.
Re: WWW::Mechanize trought a proxy for an https page
by almut (Canon) on Mar 25, 2010 at 16:19 UTC

    This issue comes up quite regularly.  See the thread WWW::Mechanize with https and a proxy  (in particular the linked AnnoCPAN note).

    The upshot of that is to set

    $mech->proxy(https => undef);

    and not use $mech->env_proxy() — at least not after having called $mech->proxy(https => undef).   env_proxy() is being called from the WWW::Mechanize constructor anyway, but explicitly undefining it afterwards overrides any settings read from the environment.

    The underlying SSLeay library will in this case read the proxy settings from the environment itself.  See Proxy Support.

    Update: just verified that even with the most recent version 5.834 of LWP::UserAgent (that WWW::Mechanize inherits the env_proxy() method from), this is still the same old issue.