Page 1 of 1

TIPEncoder question

Posted: Tue Jan 09, 2018 12:22 pm
by serge_girard
Hello,

I need to retrieve some data from a website with a URL that might contain french accents.

To build my URL I use this:

Code: Select all

cSTR        := 'Brabançonnestraat'
cBHUIS_NR   := '6'
cGEMNM      := 'LEUVEN'

oEncoder := TIPEncoder():New( "url" )
cSTR := oEncoder:Encode( cSTR)
 
url	      := 'http://loc.geopunt.be/geolocation/location?q=' + cSTR + '%20'+ cBHUIS_NR + ',' + ALLTRIM(cGEMNM)

The returned string is:
http://loc.geopunt.be/geolocation/locat ... 206,LEUVEN ==> wrong

instead of:
http://loc.geopunt.be/geolocation/locat ... 206,LEUVEN ==> good

%E7 is Windows-1252 and I need the UTF8 conversion.
How can I force the encoder to convert to UTF8?

See: https://www.w3schools.com/tags/ref_urlencode.asp
Serge

Re: TIPEncoder question

Posted: Tue Jan 09, 2018 2:33 pm
by radohabjan
Hello Serge,

I made my own conversion for Slovenian charachters:

Code: Select all

function utf8
* for check use online converter : http://www.cafewebmaster.com/online_tools/utf8_encode
parameters novtekst
novtekst=strtran(novtekst,"Č","ÄŚ")
novtekst=strtran(novtekst,"Ž","Ĺ˝")
novtekst=strtran(novtekst,"Š","Ĺ ")
novtekst=strtran(novtekst,"Ć","Ć")
novtekst=strtran(novtekst,"Đ","Đ")
novtekst=strtran(novtekst,"č","ÄŤ")
novtekst=strtran(novtekst,"ž","Ĺľ")
novtekst=strtran(novtekst,"š","š")
novtekst=strtran(novtekst,"ć","ć")
novtekst=strtran(novtekst,"đ","Ä‘")
novtekst=strtran(novtekst,"°","°")
novtekst=strtran(novtekst,"§","§")
return alltrim(novtekst)
br Rado

Re: TIPEncoder question

Posted: Tue Jan 09, 2018 3:54 pm
by serge_girard
Hi Rado,

About the same what I am doing now.

Code: Select all

         cSTR      := STRTRAN(cSTR, 'î' ,'%C3%AE')
         cSTR      := STRTRAN(cSTR, 'ï' ,'%C3%AF')
         cSTR      := STRTRAN(cSTR, 'ð' ,'%C3%B0')
         cSTR      := STRTRAN(cSTR, 'ñ' ,'%C3%B1')
         cSTR      := STRTRAN(cSTR, 'ò' ,'%C3%B2')
         cSTR      := STRTRAN(cSTR, 'ó' ,'%C3%B3')
This works but the TIPEncoder should do it also properly !

In Java it goed like this: request = URLEncoder.encode(uri+ queryParam + "&flags=X" + "&gflags=A", "UTF-8");

Serge

Re: TIPEncoder question

Posted: Tue Jan 09, 2018 9:23 pm
by edk
Hi, Serge it's simple.
First you must convert string to UTF8, then encode it.
I prefer to use the tip_URLEncode() and tip_URLDecode() functions directly, rather than the tipEncoder class:

Code: Select all

#include "hmg.ch"


#include "hblang.ch"
REQUEST HB_CODEPAGE_FRWIN

Procedure main()
SET LANGUAGE TO French
set( _SET_CODEPAGE, "FRWIN" )

cSTR        := 'Brabançonnestraat'
cBHUIS_NR   := '6'
cGEMNM      := 'LEUVEN'

//oEncoder := TIPEncoder():New( "url" )
//cSTR := oEncoder:Encode( cSTR)

cUrlEnc := tip_URLEncode( hb_StrToUTF8( cStr ) )
 
url := 'http://loc.geopunt.be/geolocation/location?q=' + cUrlEnc + ' %20' + cBHUIS_NR + ',' + ALLTRIM(cGEMNM)

msgbox(url)

return
Bez tytułu.png
Bez tytułu.png (3.04 KiB) Viewed 4005 times

Re: TIPEncoder question

Posted: Wed Jan 10, 2018 6:28 am
by serge_girard
Of course! Big thank you !

Serge