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

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
-----------------------------------------------------------------------