Stephan, Please encode your URL to UTF-8, which appears to be the recommended character set as stated at the German Wikipedia: [1]http://de.wikipedia.org/wiki/URL-Encoding I changed your program to switch to UTF-8 (1208) before calling the URL encoder. Afterwards it switches back to ASCII (819) and performs the GET request which returns the expected data, then. Hope that helps. Thomas. ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx schrieb am 21.01.2013 15:44:02: > Von: stephan.traub@xxxxxxxxx > An: ftpapi@xxxxxxxxxxxxxxxxxxxxxx, > Datum: 22.01.2013 02:28 > Betreff: Google Geocode - HTTPAPI Problem with encoding? > Gesendet von: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx > > Hello all, > > I am pretty new to use HTTPAPI and encounter a problem while trying to > connect to google geocoding api. > > It seems the problem is related to the special-characters we have in > germany. > When I try to connect to google-api with a streetname that holds for > example a "ß" as character (which nearly all streets have!) I get, > depending on the way I try to build the URL different errors. > > The URL I use to request google api is this: > [2]http://maps.googleapis.com/maps/api/geocode/xml?address=[ADDRESS]&se nsor=false > > Here now the Errors I get in different scenarios: > 1.) If I use NO encoding of the url and fill in this > "Bergstrasse+93138+Lappersdorf+DE" as address. > RESULT = OK, all perfect!!! > > 2.) If I use NO encoding of the URL and fill in this > "Bergstraße+93138+Lappersdorf+DE" as address. > RESULT = > The requested URL could not be retrieved > Invalid Request: Malformed request > Some aspect of the HTTP Request is invalid. > > 3.) If I use encoding of the URL and fill in this > "Bergstraße+93138+Lappersdorf+DE" as address. > RESULT = INVALID_REQUEST > > > I really wonder what is going wrong. > Can someone of you give me a useful hint? > > > Kind Regards > > Stephan > > --------------------------------------- > Here the code of the small program > --------------------------------------- > H DFTACTGRP(*NO) BNDDIR('LIBHTTP/HTTPAPI') > > /include LIBHTTP/QRPGLESRC,httpapi_h > /include LIBHTTP/QRPGLESRC,ifsio_h > > D QCMDEXEC PR ExtPgm('QCMDEXC') > D command 32702a const options(*varsize) > D len 15p 5 const > D igc 3a const options(*nopass) > > D GoogleResponse PR > D r likeds(resp) > D depth 10I 0 value > D name 1024A varying const > D path 24576A varying const > D value 65535A varying const > D Attrs * dim(32767) > D const options(*varsize) > > * google - Geocoding Request fields: > D req DS qualified inz > D address 150a varying > D sensor 5a varying > D key 100a varying > > * google - Geocoding Response fields: > D resp DS qualified inz > D Latitude 9p 6 > D Longitude 9p 6 > D Address 50a varying > D status 256a varying > > D Enc s like(HTTP_URL_ENCODER) > D url s 32767a varying > D filename s 50A varying > D cmd s 200A > D msg s 52A > D wait s 1A > D rc s 10I 0 > > D postData s * > D postDataSize s 10I 0 > D x s 10I 0 > > D agent s 64a > > /free > > *inlr = *on; > > // address = 'Bergstrasse 93138 Lappersdorf DE'; > req.address = 'Bergstraße+93138+Lappersdorf+DE'; > > req.sensor='false'; > > Enc = http_url_encoder_new(); > // http_url_encoder_addvar_s( enc: 'key' : req.key ); > http_url_encoder_addvar_s( enc: 'address' : req.address ); > http_url_encoder_addvar_s( enc: 'sensor' : req.sensor ); > > url = 'http://maps.googleapis.com/maps/api/geocode/xml?' > + http_url_encoder_getstr(enc); > // + 'address=' + %trimr(req.address) > // + '&sensor=false'; > http_url_encoder_free(enc); > > http_debug(*ON); > > filename = http_tempfile() + '.xml'; > rc = http_url_get( url : filename ); > if (rc < 1); > unlink(filename); > http_crash(); > return; > endif; > > dsply ('Press <ENTER> to see Google response') ' ' wait; > cmd = 'DSPF STMF(''' + filename + ''')'; > QCMDEXEC(cmd: %len(cmd)); > dsply ('Press <ENTER> to see debug log') ' ' wait; > cmd = 'DSPF STMF(''/tmp/httpapi_debug.txt'')'; > QCMDEXEC(cmd: %len(cmd)); > > // **************************************************** > // parse the XML from the temp file. > // **************************************************** > > rc =http_parse_xml_stmf( filename > : HTTP_XML_CALC > : *null > : %paddr(GoogleResponse) > : %addr(resp) ); > > unlink(filename); > if (rc < 0); > http_crash(); > return; > endif; > > // **************************************************** > // Print the news headlines & links to the full > // articles > // > // Note: If you wanted to, you could retrieve the > // articles themselves by calling http_url_get > // for each link. > // **************************************************** > > if (resp.status <> 'OK'); > http_comp(resp.status); > return; > endif; > > dsply (' Lat = ' + %char(resp.Latitude) ); > dsply (' Lon = ' + %char(resp.Longitude) ); > dsply ('Press <ENTER> to continue') ' ' wait; > > return; > > /end-free > > P GoogleResponse B > D GoogleResponse PI > D r likeds(resp) > D depth 10I 0 value > D name 1024A varying const > D path 24576A varying const > D value 65535A varying const > D attrs * dim(32767) > D const options(*varsize) > > /free > > if ( path = '/GeocodeResponse' ); > if name = 'status'; > r.status = %trimr(value); > endif; > endif; > > if ( path = '/GeocodeResponse/result/geometry/location'); > select; > when name = 'lat'; > r.latitude = %dec(value:9:6); > when name = 'lng'; > r.longitude = %dec(value:9:6); > endsl; > endif; > > if ( path = '/GeocodeResponse/result' ); > if name = 'formatted_address'; > r.address = %trimr(value); > endif; > endif; > > /end-free > P E > ----------------------------------------------------------------------- > This is the FTPAPI mailing list. To unsubscribe, please go to: > [3]http://www.scottklement.com/mailman/listinfo/ftpapi > ----------------------------------------------------------------------- -- IMPORTANT NOTICE: This email is confidential, may be legally privileged, and is for the intended recipient only. Access, disclosure, copying, distribution, or reliance on any of it by anyone else is prohibited and may be a criminal offence. Please delete if obtained in error and email confirmation to the sender. References 1. http://de.wikipedia.org/wiki/URL-Encoding 2. http://maps.googleapis.com/maps/api/geocode/xml?address= 3. http://www.scottklement.com/mailman/listinfo/ftpapi
Attachment:
googleapi_fixed.rpgle
Description: Binary data
----------------------------------------------------------------------- This is the FTPAPI mailing list. To unsubscribe, please go to: http://www.scottklement.com/mailman/listinfo/ftpapi -----------------------------------------------------------------------