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

Hello, I am brand new to perl. I am trying to create a perl script that will loggin to phpbb and post a message on a forum. Based on what I have found on the internet, this is what I have come up with.

This is the login url:
http://news.phxlab.honeywell.com/phpbb/login.php

And I believe this is important information:
<form action="login.php" method="post" target="_top">

This is the ultimate URL I want to get to:
http://news.phxlab.honeywell.com/phpbb/posting.php?mode=newtopic&f=12

And again, important information:
<form action="posting.php" method="post" name="post" onsubmit="return checkForm(this)">

Finally, here is the non-wroking code I have so far:
use strict; use HTTP::Cookies; use LWP::UserAgent; use HTTP::Request::Common; my $ua = LWP::UserAgent->new; $ua->cookie_jar(HTTP::Cookies->new(file => "cookie2.txt",autosave => 1 +,)); my $url_base = "http://news.phxlab.honeywell.com/phpbb/posting.php?mod +e=newtopic&f=12"; my $response = $ua->get($url_base); #print $response->content; my $request = HTTP::Request->new(POST=>'http://news.phxlab.honeywell.c +om/phpbb/login.php?sid=725b728e071beec160e85c81d048a151'); $request->authorization_basic('username', 'password'); my $response = $ua->request($request); my $content = $response->content; $content =~ s/\n//g;#extracting session id { print $response->content; # or whatever #print $content; }
Any help you can offer will be much appreciated. Also, if you could sort of explain what's going on, that would help to. Thanks.

Replies are listed 'Best First'.
Re: LWP::UserAgent Help
by pc88mxer (Vicar) on Jun 13, 2008 at 19:19 UTC
    I would try using WWW::Mechanize for this. You just fill in form values and it will create and issue the proper POST request for you. You would use the ->credentials() method to set up basic authorization.
      Could you point me in the direction of a sample code I could look at? And do i need to download that or should it be on my computer already?
        Just look up the documentation for WWW::Mechanize::Cookbook and WWW::Mechanize::Examples (e.g. on CPAN).
Re: LWP::UserAgent Help
by runrig (Abbot) on Jun 13, 2008 at 23:19 UTC
    A more detailed description of your problem than "not working" might be helpful (what does your code do? what does it output? where does it go wrong?). Also this makes me suspicious: return checkForm(this). checkForm is a Javascript function which could be doing anything...you may have to look at the source for that function and figure out what it's doing.
Re: LWP::UserAgent Help
by monarch (Priest) on Jun 13, 2008 at 22:26 UTC
    I must strenuously object to this exercise - there are far too many bots out there already posting unwanted advertising and spam links to phpbb sites.

    Please don't proceed with your exercise.

      That came to mind when I first read the question, but if you carefully look at the posting url it's apparent that it's for internal company use.

      At least http://news.phxlab.honeywell.com is not accessible via my ISP.