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

So, I'm writing a little bit of perl for controlling our web-based product (for testing it).

Upon first visit to the url, you get a login page.

To start with, I want to simply post the password to the silly page and get the results. It seems like this should do the trick:
use WWW::Mechanize; print "one\n"; my $mech = WWW::Mechanize->new( agent => 'Mozilla 5.0'); print "two\n" +; my $top = $mech -> get('http://10.0.0.200/'); print "three\n"; print $top->as_string; print "four\n"; print $mech->content; #$mech->set_fields( 'password' => 'secret' ); print "five\n"; #my $response = $mech->submit(); $response = $mech->submit_form( form_name => 'LoginForm', fields => { +password => "thepass" }, button => "Submit" ); print "six\n"; print $response->content;
So, I run it, and I get this:
$ perl testit.pl one two three 500 Can't connect to 10.0.0.200:80 (connect: Operation now in progress +) Content-Type: text/plain Client-Date: Fri, 18 Jul 2008 01:44:21 GMT Client-Warning: Internal response 500 Can't connect to 10.0.0.200:80 (connect: Operation now in progress +) four 500 Can't connect to 10.0.0.200:80 (connect: Operation now in progress +) five There is no form named "LoginForm" at testit.pl line 26 Died at WWW/Mechanize.pm line 1727.
The (mostly) full source of what should have been returned by the first get is here (I'd hoped that the 'readmore' tag would hide this, we'll see if it does or not):
<html> <head> <link rel="shortcut icon" href="/resources/favicon.ico" type="image/x- +icon"> <META http-equiv ....bunch of these ....> <table height="100%" align="center"> <form name="LoginForm" method="post" action="Logon"> <tr> <td> <table class="tableBordered" width="55%" border="0" cellspacing="0" ce +llpadding="5" align="center"> <tr height="15"> <td colspan="5"></td> </tr> <tr height="26"> <td width="10"></td> <td colspan="4" align="left"> <table cellspacing="0" cellpadding="0" > <tr> <td><img src="logon_icon.gif" align="center" width="20" he +ight="20"></td> <td width="10"></td> <td><b>Logon</b></td> </tr> </table> </td> </tr> <tr height="50"> <td width="10"></td> <td nowrap> Password:</td> <td> <input type="password" cols="20" name="password" value="" max +length="15" size="15"></td> <td> <input class="inputButton" type="submit" name="Submit" value= +"OK"></td> <td width="10"></td> </tr> <tr height="20"> <td colspan="5" align="center"></td> </tr> </table> </td> </tr> </form> </table> </body> </html>
By the way - you'll note that I originally tried the 'set_fields' method, but it didn't work either - it complained about 'no form defined'. IF I should have used that, I'd like to know how... So, the question is - why do I seem to be unable to get anything out of the response? Thanks! Rusty

Replies are listed 'Best First'.
Re: No response from a get or post????
by jethro (Monsignor) on Jul 18, 2008 at 02:45 UTC
    You can't access the webpage.

    See 605624

    If this does not help, check the ip address, your internet connection, test webpage access with a browser on the same machine as your script.

Re: No response from a get or post????
by pc88mxer (Vicar) on Jul 18, 2008 at 03:12 UTC
    Your problem is a low-level connectivity problem:
    500 Can't connect to 10.0.0.200:80 (connect: Operation now in progress +)
    Try setting $mech->timeout(0) and see if that fixes or changes the response. Also, make sure your web server is up and reachable - i.e. try wget or some other method to test it.

    To really debug the problem I'd have a look at the output of strace perl yourscript.pl (assuming you are on a Unix-like box.) Then we'd see what the results of the connect() calls are. I'm sure this is coming from the second connect() attempt.

    If you are on a Windows box then I have some other theories.

Re: No response from a get or post????
by Gangabass (Vicar) on Jul 18, 2008 at 07:52 UTC

    I think you just have no direct connection to this site. To access it you need to use proxy -- try to find it in your browser (from which you can access 10.0.0.200:80).