---- This is what I tried and doesn't work ----- use LWP::UserAgent; use HTML::Form; use LWP::Debug qw(+); use HTTP::Cookies; use Data::Dumper; # This site if redirected from another login page where the user # inputs a specific user/password or if the user and password is passed in , a specific cookie is sets # Assessing this page directly will have a default cookie set $site = "http://some_site_with_a_form.com"; # Creating the LWP user agent $ua = LWP::UserAgent->new; $ua->agent("Mozilla/5.0"); # Creating cookie container $cookie_jar = HTTP::Cookies->new(); $cookie_jar->set_cookie(1, "foo", "bar", "/", "http://some_site_with_a_form.com", "9000", 0, 0, 1000, 0); # tying the cookie container with the user agent $ua->cookie_jar($cookie_jar); # get the form from this site @forms = $ua->post($site); $form1 = $forms[0]; # only interested in the first form # and I can do something here to replace some values # from the form 1 but not needed for what I'm trying to show # $ua->add_cookie_header($form1.click) my $res = $ua->request($form1.click); # shows the cookie is set to default, which tells me # whatever I tried to do is useless print Dumper($res); -- It seems to work if I go into the site with the -- userid/password first which then sets the correct -- cookie use LWP::UserAgent; use HTML::Form; use LWP::Debug qw(+); use HTTP::Cookies; use Data::Dumper; # This site if redirected from another login page where the user # inputs a specific user/password or if the user and password is passed in , a specific cookie is sets # Assessing this page directly will have a default cookie set $site = "http://some_site_with_a_form.com"; # Creating the LWP user agent $ua = LWP::UserAgent->new; $ua->agent("Mozilla/5.0"); # Creating cookie container $cookie_jar = HTTP::Cookies->new(); # not needing this, just create an empty cookie container # $cookie_jar->set_cookie(1, "foo", "bar", "/", # "http://some_site_with_a_form.com", "9000", 0, 0, 1000, 0); # tying the cookie container with the user agent $ua->cookie_jar($cookie_jar); # What I have to do, pretending to go into the page with # with a password. But one can see this is lame and # very bad form to expose password $res = $ua->get($site . "?user=admin&password=adminpasswd"); ## @forms = $ua->post($site); $form1 = $forms[0]; # only interested in the first form # and I do something to replace some values from the form 1 # $ua->add_cookie_header($form1.click) my $res = $ua->request($form1.click); # shows the cookie is set for the specific user "admin print Dumper($res);