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

Re: Virgin HTTPAPI user - be gentle



That depends on what's involved in "navigating through static pages"? 
What would be easy for a human being to do isn't always easy for a 
computer (and vice-versa).

I've written applications like the one you describe (using HTTPAPI).  My 
application does this:

a) Associates my program with a profile in the Digital Certificate 
Manager (this lets me configure client certificates for my application in 
the DCM):

         https_init('KLEMENT_MYBANK_GETRECON');

b) Turns cookies on, since this is what my bank uses to track logons.

         http_use_cookies(*ON);

c) Requests my banks logon screen:

         tempfile = %str(tmpnam(*omit));

         rc = http_url_get( 'https://www.mybank.com/signin.aspx'
                          : tempfile);

d) Creates a form containing fields to be sent back to the server

         enc = http_url_encoder_new();
         http_url_encoder_addvar_s(enc: 'vtbCompanyId': CompanyID);
         http_url_encoder_addvar_s(enc: 'vtbUserId'   : UserID);
         http_url_encoder_addvar_s(enc: 'vtbPassword' : Password);

         http_url_encoder_getptr( enc: formdata: formlen );

e) POSTs the form data back to the web server

         unlink(tempfile);

         rc = http_url_post( 'https://www.mybank.com/banking/loginform.aspx'
                           : formdata
                           : formlen
                           : tempfile
                           : HTTP_TIMEOUT
                           : HTTP_USERAGENT
                           : 'application/x-www-form-urlencoded' );
         http_url_encoder_free(enc);

f) If the login is unsuccessful, the bank returns a static HTML page 
saying that it fails. If it succeeds, the bank redirects me to the pages 
where I can do stuff. (Yours may work differently than this.)

        if (RC = 1);
            unlink(TempFile);
            SetError('Login unsuccessful.');
            return *OFF;
        endif;

        dow (RC=302 or RC=303);
            URL = http_redir_loc();
            RC = http_url_get( URL : TempFile );
        enddo;

HTTPAPI returns 1 if it got a normal response (i.e. a page was returned 
for you to view).  It returns 302 or 303 if a redirect was returned.  So 
if I get a normal response I know my login failed.  If I get a redirect, 
all is well, and I get the redirected-to-loccation from HTTPAPI using the 
http_redir_loc() API, then I use http_url_get() to download that new page.

g) Now that I've logged in, I have to go to the page where the downloads 
are.  On my bank, the URL for this page is always the same, so I don't 
have to search the HTML or anything to find it.

        unlink(tempfile);

        rc = http_url_get( 'https://www.mybank.com/loggedin/download.aspx'
                         : tempfile );

h) On the page I just downloaded there's a form where you specify 
information about the file you want to download.  Once again, I use the 
URL encoder to create a web form ..  in this case, the form is always the 
same -- there's no input from the user, I just have to specify the right 
values to get the file I want.

  D FILEMODFLD      C                   '_ctl0:m_phContentArea:-
  D                                     FileModule'
  D BTNSUBMIT       C                   '_ctl0:m_phButtonArea:-
  D                                     m_btnSubmit'

      enc = http_url_encoder_new();
      http_url_encoder_addvar_s(Enc: 'submoduleId'    : '');
      http_url_encoder_addvar_s(Enc: 'clientId'       : '');
      http_url_encoder_addvar_s(Enc: 'userId'         : '');
      http_url_encoder_addvar_s(Enc: 'userkey'        : '');
      http_url_encoder_addvar_s(Enc: 'nextPage'       : '');
      http_url_encoder_addvar_s(Enc: 'pageaction'     : 'UploadFile')
      http_url_encoder_addvar_s(Enc: FILEMODFLD       : '36');
      http_url_encoder_addvar_s(Enc: BTNSUBMIT        : 'Submit');

      http_url_encoder_getptr( enc: formdata: formlen );

Yes, I realize that the pageaction says "UploadFile" and I'm talking about 
downloading a file -- but that's the way it works on my bank -- no idea 
why.

i) Now I POST this form data to the bank, and once again, it'll send me a 
redirect if all is well, or a response page if there's an error.

      RC = http_url_post( URL
                        : FormData
                        : FormLen
                        : TempFile
                        : HTTP_TIMEOUT
                        : HTTP_USERAGENT
                        : 'application/x-www-form-urlencoded' );
      http_url_encoder_free(Enc);

      dow (RC=302 or RC=303);
          URL = http_redir_loc();
          RC = http_url_get( URL : TempFile );
      enddo;

      if (RC <> 1);
         SetError( http_error() );
         unlink(TempFile);
         return *OFF;
      endif;

j) The page that I downloaded to "tempfile" in the last http_url_get() has 
a link in it to teh file I want to download.  Unfortunately, this link 
changes every time I submit the preceding form, so I have to find it in 
the tempfile and then I can download it with http_url_Get.

To find it, I open tempfile with the IFS APIs.  I load the page into 
memory (Fortunately it's under 64k so fits in an RPG variable), then I use 
%SCAN to find the link and parse it out. Yuck.

Anyway, once I have that link, I do this:

            rc = http_url_get( downloadLink
                             : '/ap/checks/reconciliation.txt');

I don't know if that helps...  what you're asking to do is a very 
complicated task.  It's hard to make a computer behave like a human being!


On Wed, 30 Aug 2006, Steve.McKay@xxxxxxxxxxx wrote:

> OK - I've downloaded the HTTPAPI product and installed it.  I would like to
> use it to automate a process which requires me to go to a website (HTTPS)
> for which I have a certificate, log-on, navigate through some static pages,
> and download a file to our IFS.  Can HTTPAPI do this?  If so, where do I
> start?  I've looked at the README member and verified that I have all of the
> LICPGMs and I've looked at the examples but am not sure whether I should be
> using one particular example or if I should be combining multiple examples
> into one program.
>
> Can someone point me in the right direction (and give me a push)?
>
> Thanks,
>
> Steve
>
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------