[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: automated login to webpage and read resulting web page



Thanks for the info Scott,

I dont seem to have what i need. I cant find WEBFORM_open(). I guess i 
have an older version of the http api.

can you tell me where i can download the most current that would include 
the "webform" logic?



On 3/30/2012 6:44 PM, Scott Klement wrote:
> hi Tim,
>
> On 3/30/2012 4:59 PM, tim.dclinc@xxxxxxxxx wrote:
>> I am looking to write an rpg program to log into a page on our server
>> and read the resulting page content. I have attached the login screen html.
> I don't understand why you're looking at the UPS Tracking example
> (EXAMPLE16 in older versions of HTTPAPI) since that calls a web service
> not a web page. Seems completely unrelated to me.
>
> As far as I can tell from your HTML, it's just asking you to submit a
> really simple form to the server.  Just create a form with the fields
> you see in the HTML, and send it to the server.
>
> Most of the junk in the HTML you posted is telling a browser how to
> display the data on the screen.  The only useful parts are these:
>
> <FORM action="/cgi-bin/kmwwrkml" method="POST">
>     <INPUT type="hidden" name="kaction" value="Sign In">
>     <INPUT type="text" name="kmbox" maxlength="10">
>     <INPUT type="password" name="kpswrd" maxlength="20">
>     <INPUT type="submit" value="Sign In">
> </FORM>
>
> There's also a Javascript in the HTML, but all it does is verify that
> the fields in the form aren't blank before you submit them, so you can
> omit that Javascript without any consequence.  So the above code is the
> only part of the screen that does anything -- everything else is just
> "how to display stuff on screen"
>
> The above form tells me:
>
> 1) The data is submitted to the /cgi-bin/kmwwrkml program on the server.
> 2) The POST method is to be used to submit it.
> 3) The form has 3 fields named kaction, kmbox, kpswrd
> 4) kaction is a hidden variable always set to 'Sign In'
> 5) kmbox (mailbox) can be up to 10 chars long.
> 6) kpswrd (password) can be up to 20 chars long.
> 7) The submit button does not have a 'name', so no value will be
>        submitted for it.
>
> So all you have to do is code the same form in your RPG program...  This
> is off the top of my head (I don't have access to a server with a screen
> like this, so I can't possibly test it)
>
>
> H DFTACTGRP(*NO) BNDDIR('HTTPAPI')
>
>    /define WEBFORMS
>    /copy httpapi_h
>
> D kmbox           s             10a
> D kpswrd          s             20a
>
> D form            s                   like(WEBFORM)
> D rc              s             10i 0
> D encodedForm     s               *
> D encodedLen      s             10i 0
>
> D QCMDEXC         PR                  ExtPgm('QCMDEXC')
> D   cmd                        200a   const
> D   len                         15p 5 const
> D   igc                          3a   const options(*nopass)
>
>    /free
>       kmbox = 'Mailbox here';
>       kpswrd = 'password here';
>
>       // Build a web form that mimics the sign-in screen:
>
>       Form = WEBFORM_open();
>       WEBFORM_setVar(form: 'kaction': 'Sign In');
>       WEBFORM_setVar(form: 'kmbox'  : kmbox    );
>       WEBFORM_setVar(form: 'kpswrd' : kpswrd   );
>
>       WEBFORM_postData( form
>                       : encodedForm
>                       : encodedLen  );
>
>       // Send to the server via the POST method
>
>       rc = http_post( 'http://example.com/cgi-bin/kmwwrkml'
>                     : encodedForm
>                     : encodedLen
>                     : '/tmp/result.html' );
>
>       WEBFORM_close(form);
>
>       if (rc<>  1);
>          http_crash();
>       endif;
>
>       // Display the data that was sent back
>       // then end program
>
>       QCMDEXC('DSPF ''/tmp/result.html''': 200);
>       *inlr = *on;
>    /end-free
>
> This is more similar to EXAMPLE2 (in old versions of HTTPAPI, or
> EXAMPLE4 in the current version) than it is to the UPS tracking example.
>
> Hopefully you understand what I'm saying...   you need to understand how
> the HTML works and what the browser will do with it so you can write RPG
> code that does the same thing.
> -----------------------------------------------------------------------
> This is the FTPAPI mailing list.  To unsubscribe, please go to:
> http://www.scottklement.com/mailman/listinfo/ftpapi
> -----------------------------------------------------------------------
>
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------