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

Hello, After having tried with curl unsuccessfully, I wonder if it is possible to post replies (being authentified of course) in a forum, like phpBB using WWW::Mechanize and this kind of parameters :
<textarea class="userform" name="message" rows="12" cols="80"></textarea> <input class="userform" value="Post this message" name="valid" accesskey="S" type="submit">
I tried several codes - that I could show in case or it is really possible - without any result. Thanks

Replies are listed 'Best First'.
Re: Post in a forum
by planetscape (Chancellor) on Aug 17, 2008 at 08:56 UTC
      Hi, I think there's a problem installing HTTP::Proxy in order to use HTTP::Recorder
      cpan[6]> install HTTP::Proxy Running install for module 'HTTP::Proxy' Running Build for B/BO/BOOK/HTTP-Proxy-0.22.tar.gz Has already been unwrapped into directory /root/.cpan/build/HTTP-Pro +xy-0.22-jA2UFx Has already been made Running Build test t/00basic...........ok t/01pod.............ok t/02pod-coverage....ok t/05new.............ok t/10init............ok t/11log.............ok t/15accessors.......ok 1/30maxconn is deprecated, please use max_conne +ctions at t/15accessors.t line 42 maxserve is deprecated, please use max_keep_alive_requests at t/15acce +ssors.t line 42 t/15accessors.......ok t/15deprecated......ok t/16stash...........ok t/17fstack..........ok t/18engine..........ok t/20dummy...........ok t/20keepalive.......ok t/22http............ok t/22transparent.....ok t/23connect.........NOK 2/4 # Failed test 'Read some data from the socket' # at t/23connect.t line 65. t/23connect.........NOK 3/4 # Failed test 'CONNECTed to the TCP server and got the banner' # at t/23connect.t line 66. # got: '' # expected: 'President_of_Earth Barbarella Professor_Ping Stomoxys + Dildano # ' t/23connect.........FAILED tests 2-3 Failed 2/4 tests, 50.00% okay t/23https...........skipped all skipped: Can't make this work with Crypt::SSLeay t/40push_filters....ok t/41filters.........ok t/42will_modify.....ok t/50hopbyhop........ok t/50standard........ok t/50via.............ok t/51simple..........ok t/51simple2.........ok t/61simple..........ok t/61simple2.........ok t/64htmltext........ok t/64lines...........ok t/64tags............ok t/66htmlparser......ok t/67complete........ok t/67save............ok t/71rot13...........ok t/90diveintomark....ok Failed Test Stat Wstat Total Fail List of Failed ---------------------------------------------------------------------- +--------- t/23connect.t 4 2 2-3 1 test skipped. Failed 1/35 test scripts. 2/473 subtests failed. Files=35, Tests=473, 51 wallclock secs ( 8.60 cusr + 1.56 csys = 10.1 +6 CPU) Failed 1/35 test programs. 2/473 subtests failed. BOOK/HTTP-Proxy-0.22.tar.gz ./Build test -- NOT OK //hint// to see the cpan-testers results for installing this module, t +ry: reports BOOK/HTTP-Proxy-0.22.tar.gz Running Build install make test had returned bad status, won't install without force Failed during this command: BOOK/HTTP-Proxy-0.22.tar.gz : make_test NO
      What could I do to solve this problem ?
Re: Post in a forum
by kyle (Abbot) on Aug 16, 2008 at 22:45 UTC

    Yes, I think WWW::Mechanize can do this. If you could show us what you've tried, that might help also.

      Thank you Here is the code I tried, after having read the documentation. To start, I just want to write "Hello" in a reply's form.
      #!/usr/bin/perl -Tw use diagnostics; use strict; use WWW::Mechanize; use HTTP::Cookies; my $mech = WWW::Mechanize->new; # $mech->cookie_jar( # HTTP::Cookies->new( # file => "/windows/C/Documents and Settings/xxx +/Application Data/Mozilla/Firefox/Profiles/xxx.default/cookies.txt", use LWP::Debug qw(+); my $url = "http://rootforum/index.php?page=post&forum=forum&category=6 +&topic=452223&option=newpost"; $mech->get($url); $mech->submit_form( form_number => 2, # the first form of the page is a search bar fields => { message => "Hello", valid => "Post this message" }, );
      And the response is :
      LWP::UserAgent::new: () LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking forum.xxx.com for cookies HTTP::Cookies::add_cookie_header: Checking .xxx.com for cookies HTTP::Cookies::add_cookie_header: Checking xxx.com for cookies HTTP::Cookies::add_cookie_header: Checking .xxx.com for cookies HTTP::Cookies::add_cookie_header: Checking xxx.com for cookies HTTP::Cookies::add_cookie_header: Checking .com for cookies LWP::UserAgent::send_request: GET http://rootforum/index.php?page=post +&forum=forum&category=6&topic=452223&option=newpost LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 555 bytes LWP::Protocol::collect: read 416 bytes LWP::Protocol::collect: read 1440 bytes LWP::Protocol::collect: read 1440 bytes LWP::Protocol::collect: read 1440 bytes LWP::Protocol::collect: read 1440 bytes LWP::Protocol::collect: read 1440 bytes LWP::Protocol::collect: read 1440 bytes LWP::Protocol::collect: read 1440 bytes LWP::Protocol::collect: read 426 bytes HTTP::Cookies::extract_cookies: Set cookie sessionforum => 471e41c7dd1 +9c424cc3277a5eb068430 LWP::UserAgent::request: Simple response: OK LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking forum.xxx.com for cookies HTTP::Cookies::add_cookie_header: - checking cookie path=/ HTTP::Cookies::add_cookie_header: - checking cookie sessionforum=471e +41c7dd19c424cc3277a5eb068430 HTTP::Cookies::add_cookie_header: it's a match HTTP::Cookies::add_cookie_header: Checking .xxx.com for cookies HTTP::Cookies::add_cookie_header: Checking xxx.com for cookies HTTP::Cookies::add_cookie_header: Checking .xxx.com for cookies HTTP::Cookies::add_cookie_header: Checking xxx.com for cookies HTTP::Cookies::add_cookie_header: Checking .com for cookies LWP::UserAgent::send_request: POST http://rootforum/index.php?page=pos +t&forum=forum&category=6&topic=452223&option=newpost LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 628 bytes LWP::Protocol::collect: read 416 bytes LWP::Protocol::collect: read 1440 bytes LWP::Protocol::collect: read 1440 bytes LWP::Protocol::collect: read 923 bytes LWP::UserAgent::request: Simple response: OK
      I havn't find the good code to submit the reply, I tried : #$mech->submit() # $mech->click_button( name => 'valid' ) # $mech->click_button( value => 'Post this message' ); I wonder if the first problem is not an authentification's one ?
        I wonder if the first problem is not an authentification's one ?

        Why? Examine the full response (headers + content (read html))

        Try to login via WWW::Mechanize and after that post message.