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

FW: Attempting to get a file using example7





   Hello all!


   I am attempting to write a program that will "get" a file from a URL.
   The site requires a user name and password.  I have successfully
   compiled and run the program listed below. When it runs it does prompt
   me for the user and then the password. It looks like it is connecting
   but it is not returning the expected results. If I access the url via
   IE I can get the file. I have tried numerous ways to format the
   http_get to no avail.



   Can anyone give me some pointers on what might be wrong?


   Any help is greatly appreciated.


   Thanks,

   Greg



   ****  program  ****  (not production ready)


     SOURCE FILE . . . . . . .  GREG/QRPGLESRC

     MEMBER  . . . . . . . . .  WWWEXAMP7


     SEQNBR*...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6
   ...+... 7 ...+... 8 ...+... 9 ...+... 0

         1      H DatFmt(*ISO) Debug(*yes)
   Option(*SrcStmt:*NoDebugIO)
            01/09/13

       100      H DFTACTGRP(*NO) ACTGRP(*NEW)
   BNDDIR('HTTPAPI')
         03/23/06


   200

       300      D/copy
   qrpglesrc,httpapi_h

       500      D rc              S             10I
   0

       600      D err             S             10I
   0

       700      D basic           S
   1N

       800      D digest          S
   1N

       900      D realm           S
   124A

      1000      D userid          S
   50A

      1100      D pass            S
   50A

      1200      D URL             s
   256A

      1300      D msg             S
   50A

      1301      d fileg           s
   25a

      1302      d geta            s
   47a

      1303      d getb            s
   17a


   1400

      1500      c                   eval      *inlr =
   *on

      1501
   C*

      1502
   /free

      1503                           http_debug
   (*on:'/temp/wweresponse.txt');

      1504
   /end-free


   1600

      1700       ** CHANGE
   THIS:

      1800       **   this has to be set to the URL of a file on a system
   that

      1900       **   requires www-authenticate, and you have an account
   for:

      2000
   **

      2001      c                   eval      geta
   =

      2002      c
   'HTTP://www.wwexf.com/keystone/ma+

      2003      c
   nifest.csv'

      2004
   c

      2005      c                   eval      getb =
   '/tmp/manifest.csv'


   2006

      2007      c                   eval      rc =
   http_url_get(geta:getb)

      2008      c*
   'HTTP://www.wwexf.com/keystone/ma+

     2009      c*
   nifest.prev.csv':

      2010      c*
   '/tmp/manifest.csv')


   2300

      2400       * The first time we request a document that requires a
   user/pass

      2500       * it will return a HTTP_NDAUTH
   error.

      2600
   *

      2700       * if that happens, we do the getpasswd
   subroutine.

      2800
   *

      2801      c                   eval      fileg =
   '/greg/testauth2.html'

      2900      c                   eval      rc = http_url_get(URL:
   fileg)

      3000      c                   if        rc <>
   1

      3100      c                   callp
   http_error(err)

      3200      c                   if        err <>
   HTTP_NDAUTH

      3300      c                   eval      msg =
   HTTP_ERROR

      3400      c                   dsply
   msg

      3500      c
   return

      3600      c
   endif

      3700      c                   exsr
   getpasswd

      3800      c
   endif


   3900

      4000
   C*-------------------------------------------------------------

      4100      C* this is called when the web server requests a
   userid/passwd

      4200
   C*-------------------------------------------------------------

      4300      csr   getpasswd
   begsr


   4400

      4500      c                   eval      rc = http_getauth(basic:
   digest: realm)

      4600      c                   if        rc <
   0

      4700      c                   eval      msg =
   HTTP_ERROR

      4800      c                   dsply
   msg

      4900      c
   return

      5000      c
   endif


   5100

      5200      c                   eval      userid = 'enter userid for '
   + realm

      5300      c                   dsply
   userid


   5400

      5500      c                   eval      pass = 'enter passwd for ' +
   realm

      5600      c                   dsply
   pass


   5700

      5800      c                   if
   Digest

      5900      c                   callp
   http_setauth(HTTP_AUTH_MD5_DIGEST:

      6000      c                                          userid:
   pass)

      6100      c
   else

      6200      c                   callp
   http_setauth(HTTP_AUTH_BASIC:

      6300      c                                          userid:
   pass)

      6400      c
   endif

      6500

      6501      c                   eval      fileg =
   '/greg/testauth.html'

      6600      c                   eval      rc = http_url_get(URL: fileg
   )

      6700      c                   if        rc <>
   1

      6800      c                   eval      msg =
   HTTP_ERROR

      6900      c                   dsply
   msg

      7000      c
   return

      7100      c
   endif


   7200

      7300      csr
   endsr



                                     * * * *  E N D  O F  S O U R C E  * *
   * *


   ***  debug respose  file ***


   HTTPAPI Ver 1.17 released 2006-09-23


   http_getauth(): entered

   http_setauth(): entered

   http_url_get(): entered

   http_persist_open(): entered

   http_long_ParseURL(): entered

   Converting relative URL.

   New URL is [1]http://www.wwexf.com/keystone/

   http_persist_get(): entered

   http_long_ParseURL(): entered

   Converting relative URL.

   New URL is [2]http://www.wwexf.com/keystone/

   do_get(): entered

   GET /keystone/ HTTP/1.1

   Host: [3]www.wwexf.com

   Authorization: Basic a2V5c3RvbmU6d29ybGR3aWRl

   User-Agent: http-api/1.17



   recvresp(): entered

   HTTP/1.1 200 OK

   Date: Thu, 10 Jan 2013 01:43:28 GMT

   Server: Apache/2.2.3 (CentOS)

   Last-Modified: Wed, 09 Jan 2013 14:16:23 GMT

   ETag: "82393f5-30-4d2dbb4fd1bc0"

   Accept-Ranges: bytes

   Content-Length: 48

   Connection: close

   Content-Type: text/html; charset=UTF-8



   SetError() #13: HTTP/1.1 200 OK

   recvdoc parms: identity 48

   header_load_cookies() entered

   recvdoc(): entered

   SetError() #0:

   <html>

   <body>

   Worldwide Express

   </body>

   </html>


   http_close(): entered


   ***  The File  /tmp/manifest.csv is created but it is empty.



   File /greg/testauth.html contains:

   <html>

   <body>

   Worldwide Express

   </body>

   </html>


   And file /greg/testauth2.html is empty











   _______________________________________________________________________

   The information contained in this electronic-mail message may be
   privileged, confidential and protected from disclosure. If you are not
   the intended recipient, any dissemination, distribution or copying is
   strictly prohibited. If you think that you have received this e-mail
   message in error please call or e-mail the sender and delete the
   message immediately. Thank you.
     __________________________________________________________________

   The information contained in this electronic-mail message may be
   privileged, confidential and protected from disclosure. If you are not
   the intended recipient, any dissemination, distribution or copying is
   strictly prohibited. If you think that you have received this e-mail
   message in error please call or e-mail the sender and delete the
   message immediately. Thank you.

References

   1. http://www.wwexf.com/keystone/
   2. http://www.wwexf.com/keystone/
   3. http://www.wwexf.com/
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------