[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Formatting an XML request and receiving the XML response
Hi Mike,
You're making two mistakes in your encoding:
a) You aren't encoding the data to make it a valid XML document. As
soon as you get an address with a < or & symbol, your XML document will
be invalid.
b) You aren't using the URL encoder properly. You've created an
encoder, but you didn't ask it to encode anything. The URL itself
contains all of the data, but if there's any characters that are invalid
in a URL (that includes blanks, &, =, /, etc) the HTTP protocol is going
to choke on it.
Mike Krebs wrote:
> Rich, I played with this app a while back (USPS address verification). Here was my test program. I didn't parse the result but look at EXAMPLE15 for how to handle that part.
>
> Mike Krebs
>
>
> H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('LIBHTTP/HTTPAPI')
>
> D/copy libhttp/qrpglesrc,httpapi_h
>
> D rc s 10I 0
> D msg s 52A
>
> d USPSUserID s 12a inz('your user id')
> 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
>
> C* retrieve the ILE RPG/400 refernece manual from IBM:
>
> c eval urlValues =
> c 'ShippingAPItest.dll?API=Verify'+
> c 'ShippingAPItest.dll?API=Verify'+
> c '&XML=<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>'
> c eval url =
> c 'http://testing.shippingapis.com/'
>
> c eval Enc = http_url_encoder_new()
> c eval rc = http_url_get(url +
> c http_url_encoder_getstr(Enc):
> 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
> ****************** End of data *****
> -----------------------------------------------------------------------
> 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
-----------------------------------------------------------------------