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

Re: HTTPAPI example for GetInfoByZIP



Hi Dan,

> However, when I try to use the API's to
> [2]http://www.webserviceX.NET/GetInfoByZIP, I don't receive any data
> past the GetInfoByZIPResponse tag.

To try it out, I wrote the following program (very quickly).  It seems 
to work just fine for me...   give it a try...

      H DFTACTGRP(*NO) BNDDIR('HTTPAPI')

      D GETZIPINFO      PR                  ExtPgm('GETZIPINFO')
      D   Zip                         15A   const
      D GETZIPINFO      PI
      D   Zip                         15A   const

       /copy httpapi_h
       /copy ifsio_h

      D GetXml          PR
      D   Info                              likeds(ZipInfo)
      D   depth                       10I 0 value
      D   name                      1024A   varying const
      D   path                     24576A   varying const
      D   value                    32767A   varying const
      D   attrs                         *   dim(32767)
      D                                     const options(*varsize)

      D rc              s             10i 0
      D SOAP            s           1000a   varying
      D soapfile        s             50a   varying
      D wait            s              1A

      D ZipInfo         ds                  qualified
      D   City                        40A   varying inz
      D   State                        2A           inz
      D   Zip                         15A   varying inz
      D   Area_Code                    3a   varying inz
      D   TimeZone                     3a   varying inz

       /free

         // ------------------------------------------------------------
         //  Create SOAP Input message:
         // ------------------------------------------------------------

         SOAP =
         '<?xml version="1.0" encoding="UTF-8"?> +
          <SOAP-ENV:Envelope +
            xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";> +
          <SOAP-ENV:Body> +
          <GetInfoByZIP xmlns="http://www.webserviceX.NET";> +
          <USZip>' + %trim(Zip) + '</USZip> +
          </GetInfoByZIP> +
          </SOAP-ENV:Body> +
          </SOAP-ENV:Envelope>';

         // Convert input message from EBCDIC -> UTF-8
         http_setCCSIDs(1208: 0);


         // ------------------------------------------------------------
         //  Send input message to service, and download response
         //  message to a temporary IFS file:
         // ------------------------------------------------------------

         soapfile = http_tempfile() + '.soap';

         rc = http_url_post( 'http://www.webservicex.net/uszip.asmx'
                           : %addr(SOAP)+2
                           : %len(SOAP)
                           : soapfile
                           : HTTP_TIMEOUT
                           : HTTP_USERAGENT
                           : 'text/xml'
                           : 'http://www.webserviceX.NET/GetInfoByZIP' );
         if (rc <> 1);
             http_crash();
         endif;


         // ------------------------------------------------------------
         //  Parse XML response
         // ------------------------------------------------------------

           rc = http_parse_xml_stmf( soapfile
                                   : HTTP_XML_CALC
                                   : *null
                                   : %paddr(GetXml)
                                   : %addr(ZipInfo) );
           unlink(soapfile);
           if (rc < 0);
               http_crash();
           endif;


         // ------------------------------------------------------------
         //  Display result:
         // ------------------------------------------------------------

         dsply ('City  = ' + ZipInfo.City);
         dsply ('State = ' + ZipInfo.State);
         dsply ('Zip   = ' + ZipInfo.Zip);
         dsply ('Area  = ' + ZipInfo.Area_Code);
         dsply ('TimZn = ' + ZipInfo.TimeZone);
         dsply ('Press ENTER to quit') ' ' wait;

         *inlr = *on;
         return;

       /end-free

      P GetXml          B
      D GetXml          PI
      D   Info                              likeds(ZipInfo)
      D   depth                       10I 0 value
      D   name                      1024A   varying const
      D   path                     24576A   varying const
      D   value                    32767A   varying const
      D   attrs                         *   dim(32767)
      D                                     const options(*varsize)
       /free
           select;
           when name = 'CITY';
              Info.City = value;
           when name = 'STATE';
              Info.State = value;
           when name = 'ZIP';
              Info.Zip  = value;
           when name = 'AREA_CODE';
              Info.Area_Code = value;
           when name = 'TIME_ZONE';
              Info.TimeZone = value;
           endsl;
       /end-free
      P                 E

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