I wound up with this code a while ago when I was troubleshooting some issues with cookies, logging into a google adwords account. I did eventually get it to work. YMMV...
my $cookie_jar = HTTP::Cookies->new; $cookie_jar->clear; # shouldn't be necessary since object was newl +y created in above line but this is all experimentation... # A variable that holds our POST request to the site $ENV{HTTPS_VERSION} = 3; my $action = POST 'https://adwords.google.com/select/LoginValidati +on', [ 'hl' => $language, 'login.userid' => $adwordsEmailLogin, 'login.password' => $adwordsPassword, 'login' => 'Login' ]; my $ua = LWP::UserAgent->new; $ua->cookie_jar($cookie_jar); # We disguise ourselves as Internet Explorer $ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); $ua->timeout(30); #$ENV{HTTPS_PROXY} = 'http://proxy.host:proxy_port'; #if need prox +y if ($proxy) { logMessage( "adwordsLogin: Logging into adwords using proxy $p +roxy.\n"); $ua->proxy('http',$proxy); # should this be https? No, seems +to work as is. # actually, not sure. check this later. } my $www = $ua->request( $action ); # In the event that the request to google fails my $headers = new HTTP::Headers; $headers = $www->headers(); my $redir = $headers->header('Location'); #target url my $action2 = GET 'https://adwords.google.com'.$redir; my $www2 = $ua->request( $action2 ); unless ($www2->is_success) { logMessage( "AdwordsLogin: The error code: " . $www2->code . " + was returned!"); } $cookie_jar->extract_cookies($www2); # Put the HTML into a seperate variable #my $content = $www2->content; # test #open F, "> adwordsLoginResult.html"; print F $content; close F; $adwordsLoginTries++; return \$cookie_jar;

In reply to Re: Passing a cookie with LWP::UserAgent by tphyahoo
in thread Passing a cookie with LWP::UserAgent by nedals

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.