Mikzu kinos wrote: > Anything you can see wrong with this? I NEVER see anything in cookies.txt... > > #!/usr/bin/perl -W > use LWP::UserAgent; > use HTTP::Cookies; > use HTTP::Request; > use strict; > > my $ua = LWP::UserAgent->new; > $ua->cookie_jar(HTTP::Cookies->new(file => 'cookies.txt', autosave => 1)); > > my $res = $ua->request(HTTP::Request->new(GET => 'http://www.test.com')); > > my $req = HTTP::Request->new(POST => ''); > $req->content_type('application/x-www-form-urlencoded'); > $req->content('ulogin=x&upassword=x'); > $res = $ua->request($req); > > open my $file, ">test.html" or die "Couldn't open test.html: $!"; > print $file $res->as_string; > close $file;
The code below sets this cookie for me in the cookie file (using either a GET [if (1)] or POST [if (0)]): Set-Cookie3: Fubar="a%3A1%3Ab%3A1"; path="/"; domain="localhost4.local"; path_spec; expires="2006-04-21 00:12:21Z"; version=0 use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request; my $url = 'http://localhost4/cgi-bin/cookie.pl'; my $ua = LWP::UserAgent->new; $ua->cookie_jar(HTTP::Cookies->new(file => 'cookies.txt', autosave => 1)); my $req; if (0) { # set to 1 for GET - 0 for POST $req = new HTTP::Request('GET', $url); } else { if (0) { # set to 1 for alternate POST form $req = HTTP::Request->new(POST => $url); $req->content_type('application/x-www-form-urlencoded'); $req->content('ulogin=x&upassword=x'); } else { use HTTP::Request::Common qw(POST); $req = POST $url, Content_Type => 'form-data', Content => [ ulogin => 'x', password => 'y' ]; } } print "Getting $url\n"; my $res = $ua->request($req); open OUT, ">test.html" or die "Couldn't open test.html: $!"; print OUT "Request made to $url at ", scalar localtime, "\n"; print OUT $res->as_string; my $content = $res->as_string; print length $content, "\n"; __END__ -- ,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED] (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff) _______________________________________________ ActivePerl mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
