Re: Cookies for LWPng
Gisle Aas (gisle@activestate.com)
14 Sep 2000 12:47:57 +0200
"Tan Joo Geok" <tjg@krdl.org.sg> writes:
> I have been using the LWPng distribution which implements HTTP/1.1. I am wondering how to get the Cookie operations working for LWPng. I tried doing this:
>
>
> #!/usr/bin/perl -w
>
> require LWP;
> require LWP::Debug;
>
> use LWP::UA;
> use LWP::UA::Cookies;
> use LWP::Request;
> use LWP::MainLoop qw(mainloop);
> use HTTP::Cookies;
>
> $ua = LWP::UA->new;
> $ua->agent("Mozilla/8.0");
> $ua->cookie_jar(HTTP::Cookies->new);
>
> $url = "http://www.hotmail.com";
> $timeout = 3*60;
> $request = LWP::Request->new("GET");
> $request->{'done_cb'} = sub { $response = shift;};
> $request->url($url);
> $ua->spool($request);
> mainloop->one_event($timeout) until $response;
> if ($response)
> {
> print "Main page done for $url\n";
> if ($ua->cookie_jar->as_string)
> {
> print "Cookies found\n";
> }
> else
> {
> print "No Cookies found\n";
> }
> }
>
>
> The error message I get is:
>
> Can't locate object method "epath" via package "URI::http" at /usr/lib/perl5/site_perl/5.005/HTTP/Cookies.pm line 110.
>
> Does anybody know what is the problem?
The problem is URI::URL --> URI migration. LWPng use URI while LWP5
still use the old URI::URL interface.
The epath() method of URI::URL is basically the same as path() of URI,
while path() in URI::URL is different. Therefore I can't just change
HTTP::Cookies to call path.
Try to add a:
sub URI::epath { shift->path(@_); }
to you application.
Regards,
Gisle