in reply to POSTing information on a web page

You need to send the session cookie(s) back with every page request. If you look at the response you will see your login tokens:

Set-Cookie: PHPSESSID=rl6oeo664r7g9lnd7gin5ilvn3; path=/ Set-Cookie: fusion_user=24236.f31e0a8a2cefed417ec46c7675e4142d; expires=Mon, 16 Jun 2008 16:48:06 GMT; path=/

These tokens are how the server knows you logged in. Just set up a HTTP::Cookies cookie jar and it will work fine. If you want the executive answer (using your first example):

use LWP::UserAgent; use HTTP::Cookies; # not actually required as LWP uses it, # so you don't need to use it again.... $agent = LWP::UserAgent->new; $agent->cookie_jar( {} ); # temporary cookie jar $agent->agent( [snip]

Replies are listed 'Best First'.
Re^2: POSTing information on a web page
by Corion (Patriarch) on Jun 16, 2008 at 15:10 UTC

    ... or just use WWW::Mechanize, which also does the cookie handling transparently.

Re^2: POSTing information on a web page
by clone4 (Sexton) on Jun 16, 2008 at 17:36 UTC
    thanks a lot, didn't realise this, well I have to get my head around how to use the module correctly, I guess I will have to get the cookie from the respond using regex, and then pass it before GETing the page again... my god, that will be long night :)

      You're still thinking far too low-level about things. Read the WWW::Mechanize documentation. It does the cookie handling for you completely. You can even save the cookie jar to disk so you don't need to log in again the next time your script runs.

      If you insist on doing things yourself, consider using HTTP::Cookies instead of extracting the cookie information yourself. But then, LWP::UserAgent already does that for you.

      No No No. For a start modules have methods to do stuff: ie $lwp->cookie_jar->extract_cookies($response) However LWP takes care of this for you. *All you need to do is setup the cookie jar as shown*. The cookies you are sent will automatically be included in the header sent by LWP as appropriate. Note that in LWP the cookie_jar() method is actually just a reference to an HTTP::Cookies object so you can call any HTTP::Cookies method on $lwp->cookie_jar. Although you don't generally need to do it WWW::Mechanize is a subclass of LWP::UserAgent so (more or less) anything you can do with an LWP object (in terms of calling methods) you can do with your Mech object (unless that method got overridden).

      If you are "stopping and starting" your program you can avoid logging in every time you run the program by saving the cookie to disk. See the docs, read them, and understand them.

        thanks that helped the most. Sry for my 'slow' :) understanding, I'm new to all that stuff as well as perl ( even though i shouldn't use it as a excuse...)