my $cookie_jar = HTTP::Cookies->new; $cookie_jar->clear; # shouldn't be necessary since object was newly 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/LoginValidation', [ '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 proxy if ($proxy) { logMessage( "adwordsLogin: Logging into adwords using proxy $proxy.\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;