Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Seeking assistance with WWW::Mechanize Form Submission

by Gangabass (Vicar)
on Jan 15, 2013 at 01:09 UTC ( [id://1013298]=note: print w/replies, xml ) Need Help??


in reply to Seeking assistance with WWW::Mechanize Form Submission

First I recommend you to start by checking if your form works in the browser with JavaScript disabled: remove all cookies for this site, disable JavaScript and try to submit your form.

If the problem is not in JavaScript you need to try to add button => ... to your code. Many sites expects x and y coordinates of the submit button you click:

$mech->submit_form( with_fields => { "login_username" =>'username', "login_password" => 'password', "prefLanguage" => '00000000', }, button => "your_submit_button_name", );
to your code. Many sites expects x and y coordinates of the submit button you click:

Replies are listed 'Best First'.
Re^2: Seeking assistance with WWW::Mechanize Form Submission
by tspang (Initiate) on Jan 15, 2013 at 16:30 UTC

    I removed all existing cookies, disabled javascript and cookies in firefox prior to logging in, and was still able to successfully log in, so it doesn't look like javascript or cookie issue (even though the site does set a cookie per HTTP Watch).

    I changed the structure of my form submission to this:

    $mech->submit_form( form_name => 'HashForm1', fields => { login_password => 'username', login_username => 'password', prefLanguage => '00000000', }, button => "submit", );
    Still to no success. Is the above code functionally different than what I had been using earlier?
    $mech->form_name('HashForm1'); $mech->field("login_username",'username'); $mech->field("login_password",'password'); $mech->field("prefLanguage",00000000); $mech->submit_form();

    Thanks for the help so far, everyone. I'm looking into HTTP:Recorder right now, and I'm feeling like I'm moving at least a little toward a solution at this point.

      Are you sure that your submit button is named "submit"? Yes, the code is different (you're now sending button info too).

      I recommend you to use LiveHttpHeaders for Firefox and make exactly same request with $mech->post()

      Thanks.
      Roman

        I'm using HTTP Watch through IE (I'm somewhat limited in what I can use in my corporate enviornment) to capture the data from the form submission -- I assume that HTTP Watch will capture the same data as LiveHttpHeaders. Here is the post data as captured by HTTP Watch:

        paramater value size login_password passoword 18 login_username username 18 prefLanguage 00000000 21 submit Log On 13
        and here is the only cookie (which doesn't seem necessary since I can log in with cookies turned off)
        Name Direction Value Path Domain Duration C0 Sent apc / .192.168.0.2 (Session) HTTP Only Secure No Yes
        and, finally, here is the header information
        Header Sent Value (Request-Line) POST /Forms/login1 HTTP/1.1 Accept application/x-ms-application, image/jpeg, application/xaml+x +ml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms +-excel, application/vnd.ms-powerpoint, application/msword, */* Accept-Encoding gzip, deflate Accept-Language en-US Cache-Control no-cache Connection Keep-Alive Content-Length 73 Content-Type application/x-www-form-urlencoded Cookie C0=apc Host 192.168.0.2 Referer https://192.168.0.2/logon.htm User-Agent Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64 +; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CL +R 3.0.30729; .NET4.0C; MS-RTC LM 8; InfoPath.2)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1013298]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found