#!/usr/lib/perl use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request::Common; use HTTP::Headers; #is this where I declare cookie_jar?? seems like I am doing it twice my $cookie_jar = HTTP::Cookies->new; my $ua = LWP::UserAgent->new; #but it seems like I am nearly doing the same thing here #but I need the variable below for add_cookie_header and extract_cookies $ua->cookie_jar(HTTP::Cookies->new(file => 'cookie_jar', autosave =>1)); my $request = $ua->simple_request(POST "http://www.sitedomain.com/login.cfm", { username =>'abcuser', userpass =>'abc123', submit =>'Submit' }); while ($request->is_redirect) { my $u = $request->header('location') or die "missing location: ", $request->as_string; #print "redirecting to $u\n"; $u=~s/^\.+/http\:\/\/www\.sitedomain\.com/s; $request = $ua->simple_request(GET $u); } #do this before extract? is that the right variable to do it on? #HTTP::Cookies says that add_cookie_header must have a "valid url attribute". #that lingo doesn't click with me $cookie_jar->add_cookie_header($request); my $response = $ua->request($request); $cookie_jar->extract_cookies($response); $ua->cookie_jar($cookie_jar); my $request = $ua->simple_request(POST "http://www.sitedomain.com/page.cfm", { firstname =>"Michael", lastname =>"Jensen", company =>"companyname", address =>"111 East 222 South", city =>"Provo", state =>"UT", zip =>"99999" }); if ($request->is_success) { $a = "worked"; } else{ $a = "failed"; } print "$a";