LWP and cookies

LWP and cookies

am 29.08.2005 11:48:16 von thesaltydog

I am writing an application with LWP::UserAgent. From the web I can
authenticate on a form and then post some data on a second form.
From perl, the authentication is working fine, but as soon as I get
next form url, I receive from the server a "session timeout" message.
In my program I am using memory-cookies:

my $ua =3D LWP::UserAgent->new(); # Create user agent object
$ua->cookie_jar({}); # Cookie handling object
$ua->agent('Mozilla/5.0'); # User agent property

Re: LWP and cookies

am 29.08.2005 11:58:27 von gisle

The Saltydog writes:

> I am writing an application with LWP::UserAgent. From the web I can
> authenticate on a form and then post some data on a second form.
> >From perl, the authentication is working fine, but as soon as I get
> next form url, I receive from the server a "session timeout" message.
> In my program I am using memory-cookies:
>
> my $ua = LWP::UserAgent->new(); # Create user agent object
> $ua->cookie_jar({}); # Cookie handling object
> $ua->agent('Mozilla/5.0'); # User agent property

Which should work fine. I suggest you try a network sniffer program
(like ethereal) to figure out what is different when the brower talks
to the server than when LWP does.

Regards,
Gisle

Re: LWP and cookies

am 29.08.2005 12:08:49 von thesaltydog

On 29 Aug 2005 02:58:27 -0700, Gisle Aas wrote:
> Which should work fine. I suggest you try a network sniffer program
> (like ethereal) to figure out what is different when the brower talks
> to the server than when LWP does.

From ethereal's analysis I can see that cookies are correctly sent.
The difference I can notice is on a "Connection:" field which from the
web is: keep-alive, while from LWP is: close...
What does it mean?

Re: LWP and cookies

am 29.08.2005 12:27:14 von thesaltydog

On 8/29/05, The Saltydog wrote:
>=20
> From ethereal's analysis I can see that cookies are correctly sent.
> The difference I can notice is on a "Connection:" field which from the
> web is: keep-alive, while from LWP is: close...
> What does it mean?
>=20


I have added this, just before the $ua->get :

$ua->default_header('Connection' =3D> "Keep-Alive");

but now with ethereal I have:

Connection: Keep-Alive, close

The "close" is still there..

Re: LWP and cookies

am 29.08.2005 12:38:34 von gisle

The Saltydog writes:

> On 8/29/05, The Saltydog wrote:
> >
> > From ethereal's analysis I can see that cookies are correctly sent.
> > The difference I can notice is on a "Connection:" field which from the
> > web is: keep-alive, while from LWP is: close...
> > What does it mean?
> >
>
>
> I have added this, just before the $ua->get :
>
> $ua->default_header('Connection' => "Keep-Alive");
>
> but now with ethereal I have:
>
> Connection: Keep-Alive, close
>
> The "close" is still there..

Try to set up the $ua with:

$ua = LWP::UserAgent->new(keep_alive => 1);

Regards,
Gisle

Re: LWP and cookies

am 29.08.2005 12:46:50 von thesaltydog

On 29 Aug 2005 03:38:34 -0700, Gisle Aas wrote:
> Try to set up the $ua with:
>=20
> $ua =3D LWP::UserAgent->new(keep_alive =3D> 1);


Thanks! Now the connection is Keep-Alive, as from the web.
Unfortunately, still doesn't work, so I will investigate more..

Re: LWP and cookies

am 29.08.2005 15:51:20 von gedanken

On Mon, 29 Aug 2005, The Saltydog wrote:

I will guess that a cookie is being set by javascript, which would explai
nwhy it fails in lwp but works in a browser. If you read through the
source code and find what they set, or find it from a header sniffer like
httpliveheaders plugin for mozilla, you can set them manually.

$agent->cookie_jar()->set_cookie(1, "cookieMissing", "valueI
snaggedOffPageManually", "/",
"foo.com");

matt

On 29 Aug 2005 03:38:34 -0700, Gisle Aas wrote:
> Try to set up the $ua with:
>
> $ua = LWP::UserAgent->new(keep_alive => 1);


Thanks! Now the connection is Keep-Alive, as from the web.
Unfortunately, still doesn't work, so I will investigate more..


--
gedanken