in reply to Mechanize:submit_form issue.

Since you seem to be using autocheck, you should write your program like this
#!/usr/bin/perl -- use strict; use warnings; use WWW::Mechanize 1.60; #implies autocheck => 1 my $url = 'http://host:7777/fagcs_302_C600_sfosun05/domain/'; #my $url = 'http://host:7778/fagcs_320_C106_sfoaix04/domain/'; my $username = 'usrname'; my $password = 'pswd'; my $agent = WWW::Mechanize->new( autocheck => 1 ); if ( eval { $agent->get($url); 1 } ) { eval { $agent->submit_form( form_number => 0, fields => { 'j_username' => $username, 'j_password' => $password, }, ); 1; } or do { print "error :($@)\n"; print "Couldn't submit form:" . $agent->status() . ":" . ":" . $agent->content() . "\n"; }; }
The error "500 Server closed connection without sending any data back" indicates a problem with the server. You should try to see if it works from a browser like Firefox (Firebug), and if it does, you should install livehttpheaders, and compare what firefox sends to what your program(mechanize) sends.

Replies are listed 'Best First'.
Re^2: Mechanize:submit_form issue.
by perlcoding (Initiate) on Sep 16, 2009 at 15:52 UTC
    Hello folks, thanks for the replies.
    I wasn't able to test the suggestion you provided.
    I shall hope to try out your suggestions by EOD tommorow.

    My special thanks to the anonymous monk,that is something new to me.

    Will update you folks on the same.

      Hey folks please help me.
      Its a critical task for me now.
      Now the script is throwing this error message
      "Error POSTing http://host:12501/adhoc_sfosun05/login/login.do"
      What should we understand when we get "Error POSTing". I can't seem to get around with this task.
      Seems like when script executes submit_form statement than it throws the above message.
      Please help me.

        Hey anonymous,
        I have added the handler for 'request_send' and 'response_done',let me know if you need something else, here's the dump of that.

        GET http://blraix02:7779/adhoc_sfosun05/domain/
        Accept-Encoding: gzip
        User-Agent: WWW-Mechanize/1.60

        (no content)
        HTTP/1.1 209 Unknown code
        Cache-Control: no-cache, must-revalidate, max_age=0, no-store
        Connection: close
        Date: Mon, 05 Oct 2009 12:10:50 GMT
        Pragma: no-cache
        Server: Oracle-Application-Server-10g/10.1.2.0.2 Oracle-HTTP-Server
        Content-Length: 4306
        Content-Location: http://blraix02:12501/adhoc_sfosun05/login/login.jsp
        Content-Type: text/html; charset=UTF-8
        Expires: -1
        Client-Date: Mon, 05 Oct 2009 12:10:50 GMT
        Client-Peer: 172.16.65.159:7779
        Client-Response-Num: 1
        Link: </adhoc_sfosun05/common/css/style.css>; /="/"; rel="stylesheet"; type="text/css"
        Set-Cookie: JSESSIONID=ac10419f30d5e6d7c0fd848c4e2ab559f572b24e38a5.e34Pc30SaxqPb40La30Sa30TaxuTe6fznA5Pp7ftolbGmkTy; path=/adhoc_sfosun05
        Title: Welcome to TECH Solutions

        \n\n\n\n
        <html>
        <head>
        <title>Welcome to TECH Solutions</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" href="/adhoc_sfosun05/common/css/style.css" type="text/css" />
        <script language="javascript" type="text/javascript" src="/adhoc_sfosun05/common/js/Main.js"></script>
        <script language="javascript" type="text/javascript" src="/adhoc_sfosun05/common/js/App.js"></script>
        <script language="javascript" type="text/javascript" src="/adh...
        (+ 3794 more bytes not shown)
        POST http://blraix02:12501/adhoc_sfosun05/login/login.do
        Accept-Encoding: gzip
        Referer: http://blraix02:7779/adhoc_sfosun05/domain/
        User-Agent: WWW-Mechanize/1.60
        Content-Length: 23
        Content-Type: application/x-www-form-urlencoded
        Cookie: JSESSIONID=ac10419f30d5e6d7c0fd848c4e2ab559f572b24e38a5.e34Pc30SaxqPb40La30Sa30TaxuTe6fznA5Pp7ftolbGmkTy
        Cookie2: $Version="1"

        j_username=&j_password=
        500 Server closed connection without sending any data back
        Content-Type: text/plain
        Client-Date: Mon, 05 Oct 2009 12:10:51 GMT
        Client-Warning: Internal response

        500 Server closed connection without sending any data back\n

        And this error is thrown by the script
        'Error POSTing http://blraix02:12501/adhoc_sfosun05/login/login.do: Server closed connection without sending any data back at testwrk.pl line'