FireBird34 has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,

I'm creating an app using Tk for a forum moderator tool. I have the GUI created, and the tool almost done; minus the big issue. I am unable to 'trick' the forum (VBulletin) into 'thinking' that I am logged in.

I will use the tool while logged in, and I will pass my login credentials while attempting to do an action. Same result; return output is that I am not logged in. Any thoughts on how to have an app register a cookie (or other thoughts)?

Here is what I'm trying:
my $browser = LWP::UserAgent->new; my $loginUrl = 'http://forum.webpage.com/index.php'; #my login credentials my $loginResponse = $browser->post ($loginUrl, [ 'action' => 'login', 'username' => 'my use +rname', 'password' => 'my pas +sword' ] ); die "$loginUrl error: ", $loginResponse->status_line unless $loginResponse->is_success; die "Weird content type at $loginUrl -- ", $loginResponse->content_typ +e unless $loginResponse->content_type eq 'text/html'; print "First resp: ".$loginResponse->content."\n"; # ban user my $banUrl = 'http://forum.webpage/mod/ban.php'; my $banResponse = $browser->post ($banUrl, 'banUser' => "username here +" ); die "$banUrl error: ", $banResponse->status_line unless $banResponse->is_success; die "Weird content type at $banUrl -- ", $banResponse->content_type unless $banResponse->content_type eq 'text/html'; print "Second resp: ".$banResponse->content."\n";
$loginResponse->content gives me the HTML output as if I wasn't logged in yet

$banResponse->content gives me the output "You are not logged in"

So this makes me think it's just a cookie issue through Tk. Been quite some time since I've worked with Tk, so any and all help is appreciated.

Replies are listed 'Best First'.
Re: app not storing cookies (using LWP::UserAgent)
by CSJewell (Beadle) on Apr 16, 2009 at 14:44 UTC

    I don't see any place where you're telling $browser to use cookies at all!

    To do so, assuming you can discard the cookies once $browser is gone, you can do this:

    my $browser = LWP::UserAgent->new; $browser->cookie_jar({}); ...

    If that's not the case, pass in an HTTP::Cookies object (or an object that subclasses that class) or provide appropriate options within the hashref instead of just using an empty hashref (LWP::UserAgent->cookie_jar() assumes that a hashref is options to create an HTTP::Cookies object for itself.

      I think I'm able to get the cookie passed now, however for some reason, browser is not accepting it still. Curious to know if 'Set-Cookie3' matters or not when pushing the cookie? If so, how am I able to set it to 1 or 2?

      updated code -- different area in the code for my sanity (to make sure cookie actually takes).
      my $ua = LWP::UserAgent->new; my $cookie_jar = HTTP::Cookies->new(); $cookie_jar->load("test.txt"); $ua->cookie_jar(); my $banUrl = 'http://website.com/mod/ban.php'; my $request = $ua->request(POST "$banUrl", { banUser => 'name here', submitBan => 'Ban User' }); if($request->is_success){ print "worked\n"; }else{ print "failed\n"; } print "Content: ".$request->content."\n";
      The result is that it 'worked', however the 'content' reply is not logged in still. Something simple I'm sure, but I'm racking my brain searching for this.

      My 'test.txt' file is in Set-Cookie3 format (the default)