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

RE: USPS example was Formatting an XML request and receiving the XML response



New version of program (switched to free and using get_XML to parse result) ...

     H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('LIBHTTP/HTTPAPI')

     D/copy libhttp/qrpglesrc,httpapi_h

     D rc              s             10I 0
     D rc2             s               n
     D msg             s             52A

     d USPSUserID      s             12a    inz('USPSUserID')
     d address1        s             38a    inz(*blanks)
     d address2        s             38a    inz('6406 Ivy Lane')
     d city            s             15a    inz('Greenbelt')
     d state           s              2a    inz('MD')
     d zip5            s              5a    inz(*blanks)
     d zip4            s              4a    inz(*blanks)

     d o               ds                   qualified
     d   address1                           like(address1)
     d   address2                           like(address2)
     d   city                               like(city)
     d   state                              like(state)
     d   zip5                               like(zip5)
     d   zip4                               like(zip4)

     d Enc             s                    like(HTTP_URL_ENCODER)
     d url             s          32767a    varying
     d urlValues       s          32767a    varying
     d addressRequest  s          32767a    varying
     d bigString       s          32767a    varying

     D*--------------------------------------------------
     D* Procedure name: Incoming
     D* Purpose:        Parse return address into data structure
     D* Returns:
     D* Parameter:      userData
     D* Parameter:      depth
     D* Parameter:      name
     D* Parameter:      path
     D* Parameter:      attrs
     D*--------------------------------------------------
     D Incoming        PR
     D  userData                       *   VALUE
     D  depth                        10I 0 VALUE
     D  name                       1024A   VARYING
     D                                     CONST
     D  path                      24576A   VARYING
     D                                     CONST
     D  value                     65535A   VARYING
     D                                     CONST
     D  attrs                          *   DIM(32767)
     D                                     CONST
     D                                     OPTIONS(*VARSIZE)


      /FREE
       http_debug(*on);
       url = 'http://testing.shippingapis.com/';
       addressRequest =
           '<AddressValidateRequest '+
           'USERID="' + %trim(USPSUserID) + '">' +
           '<Address ID="0">'+
           '<Address1>' + %trim(Address1) +
           '</Address1>' +
           '<Address2>' + %trim(Address2) +
           '</Address2>' +
           '<City>' + %trim(City) +
           '</City>' +
           '<State>' + %trim(State) +
           '</State>' +
           '<Zip5>' + %trim(Zip5) +
           '</Zip5>' +
           '<Zip4>' + %trim(Zip4) +
           '</Zip4>' +
           '</Address></AddressValidateRequest>';
       // encode the address request
       Enc = http_url_encoder_new();
       rc2 = http_url_encoder_addvar( Enc:
           'XML':
           %addr(addressRequest) + 2:
           %len(addressRequest));
       bigString = http_url_encoder_getstr( Enc );
       urlValues =
           'ShippingAPItest.dll?API=Verify&' +
           bigString;
       // send request
       rc = http_get_xml(url +  urlValues:
           *null: %paddr(Incoming): *null );
       if rc <> 1;
         msg = http_error;
         dsply msg;
       Else;

       endif;

       http_url_encoder_free(Enc);

       *inlr = *on;
      /END-FREE

     P*--------------------------------------------------
     P* Procedure name: Incoming
     P* Purpose:        Parse return address into data structure
     P* Returns:
     P* Parameter:      userData
     P* Parameter:      depth
     P* Parameter:      name
     P* Parameter:      path
     P* Parameter:      attrs
     P*--------------------------------------------------
     P Incoming        B
     D Incoming        PI
     D  userData                       *   VALUE
     D  depth                        10I 0 VALUE
     D  name                       1024A   VARYING
     D                                     CONST
     D  path                      24576A   VARYING
     D                                     CONST
     D  value                     65535A   VARYING
     D                                     CONST
     D  attrs                          *   DIM(32767)
     D                                     CONST
     D                                     OPTIONS(*VARSIZE)


      /FREE

       Select;
         when name    = 'Address1';
           o.address1 = value;
         when name    = 'Address2';
           o.address2 = value;
         when name    = 'City';
           o.city     = value;
         when name    = 'State';
           o.state    = value;
         when name    = 'Zip5';
           o.zip5     = value;
         when name = 'Zip4';
           o.zip4     = value;
       EndSl;
      /END-FREE
     P Incoming        E           

> -----Original Message-----
> From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-
> bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Mike Krebs
> Sent: Wednesday, June 24, 2009 2:38 PM
> To: HTTPAPI and FTPAPI Projects
> Subject: USPS example was Formatting an XML request and receiving the
> XML response
> 
> For those following the USPS address verification example, this code
> appears to work (it encodes the XML being sent). Because the encoding
> is happening on the entire XML string, you would still need to clean
> the data before sending it through this routine. Specifically, you
> would replace any < or > characters that are in your data (probably
> with blanks). I didn't experiment much beyond that to see what specific
> characters may cause problems.
> 
> Mike Krebs
> 
> If you need a user ID, get it from here:
> https://secure.shippingapis.com/registration/
> 
> 
> H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('LIBHTTP/HTTPAPI')
>  * Use the United States Postal Service address verification function
> 
> D/copy libhttp/qrpglesrc,httpapi_h
> 
> D rc              s             10I 0
> D rc2             s               n
> D msg             s             52A
> 
> d USPSUserID      s             12a    inz('USPSUserID')
> d address1        s             38a    inz(*blanks)
> d address2        s             38a    inz('6406 Ivy Lane')
> d city            s             15a    inz('Greenbelt')
> d state           s              2a    inz('MD')
> d zip5            s              5a    inz(*blanks)
> d zip4            s              4a    inz(*blanks)
> 
> d Enc             s                    like(HTTP_URL_ENCODER)
> d url             s          32767a    varying
> d urlValues       s          32767a    varying
> d addressRequest  s          32767a    varying
> d bigString       s          32767a    varying
> 
> C* retrieve the ILE RPG/400 refernece manual from IBM:
> 
> c                   callp     http_debug(*on)
> c                   eval      url       =
> c                             'http://testing.shippingapis.com/'
> c                   eval      addressRequest =
> c                             '<AddressValidateRequest '+
> c                             'USERID="' + %trim(USPSUserID) + '">' +
> c                             '<Address ID="0">'+
> c                             '<Address1>' + %trim(Address1) +
> c                                  '</Address1>' +
> c                             '<Address2>' + %trim(Address2) +
> c                                  '</Address2>' +
> c                             '<City>' + %trim(City) +
> c                                  '</City>' +
> c                             '<State>' + %trim(State) +
> c                                  '</State>' +
> c                             '<Zip5>' + %trim(Zip5) +
> c                                  '</Zip5>' +
> c                             '<Zip4>' + %trim(Zip4) +
> c                                  '</Zip4>' +
> c                             '</Address></AddressValidateRequest>'
>  * encode the address request
> c                   eval      Enc = http_url_encoder_new()
> c                   eval      rc2 = http_url_encoder_addvar( Enc:
> c                              'XML':
> c                              %addr(addressRequest) + 2:
> c                              %len(addressRequest))
> c                   eval      bigString = http_url_encoder_getstr( Enc
> )
> c                   eval      urlValues =
> c                             'ShippingAPItest.dll?API=Verify&' +
> c                             bigString
> c                   eval      rc = http_url_get(url +  urlValues:
> c                             '/tmp/address_valid.txt')
> c                   if        rc <> 1
> c                   eval      msg = http_error
> c                   dsply                   msg
> c                   endif
> 
> c                   callp     http_url_encoder_free(Enc)
> 
> c                   eval      *inlr = *on
> -----------------------------------------------------------------------
> 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
-----------------------------------------------------------------------