Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^4: Seeking assistance with WWW::Mechanize Form Submission

by tspang (Initiate)
on Jan 16, 2013 at 14:39 UTC ( #1013583=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Seeking assistance with WWW::Mechanize Form Submission
in thread Seeking assistance with WWW::Mechanize Form Submission

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)


Comment on Re^4: Seeking assistance with WWW::Mechanize Form Submission
Select or Download Code
Re^5: Seeking assistance with WWW::Mechanize Form Submission
by Anonymous Monk on Jan 16, 2013 at 15:41 UTC
    And then what? How are the two different?
Re^5: Seeking assistance with WWW::Mechanize Form Submission
by Gangabass (Priest) on Jan 17, 2013 at 13:27 UTC

    Try this:

    $mech->submit_form( ..... fields => { ..... submit => "Log On", }, ),
      using these 3 variations:
      $data=$mech->submit_form( form_name => 'HashForm1', fields => { login_password => 'password', login_username => 'username', prefLanguage => 00000000, submit => 'Log On', } );
      and this
      $mech->submit_form( form_name => 'HashForm1', fields => { login_password => 'password', login_username => 'username', prefLanguage => 00000000, }, button => "submit", );
      and this
      $mech->form_name('HashForm1'); $mech->field("login_username",'username'); $mech->field("login_password",'password'); $mech->field("prefLanguage",00000000); $mech->submit_form();

      all yield the same 500 error. Trying to record the tranactions using httprecorder with the follwing line yields a 403

      $mech->proxy(['https'], 'http://localhost:8080');

      but it does yield this in the log:

      $agent->get('https://192.168.0.2'); $agent->get('https://192.168.0.2/home.htm'); $agent->get('https://192.168.0.2/logon.htm');

      I have tried all of the different combinations of submitting the post data as well, even though that seemed like the least likely way to resolve the problem. Is it possible something in the headers isn't being set that would prevent log in? This seems like such a simple task and yet its turning out to be quite difficult.

        Try to set User-Agent (at the beginning of your code):

        $mech->agent_alias("Windows IE 6");

        This seems like such a simple task and yet its turning out to be quite difficult.

        It is because you're not being linear, because you're not speaking the right language

        If it works from your browser, it works because of the headers/requests it sends, so if you want it to work from LWP, send the exact same requests, in the exact same order, using the exact same headers

        If for whatever reason the website decides it doesn't like your requests, you didn't dot an I or cross a T, well, you'll have to figure it out, there is no secret, no magic, websites can be fantastically stupid in what they accept and what they reject, so if you have found a way that works, be as identical as possible

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (13)
As of 2014-09-18 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (120 votes), past polls