Romanian Encoding

Hello Everyone,

I am working on a project that will work in the Romanian Market. My project will connect through Xojo.Net.HTTPSocket with the ECR.
The ECR service is having ISO-8859-16 encoding on all its Socket Communications. That means that if i try to send a Text
using Romanian characters the ECR cannot understand what i am sending to it and when the ecr replies to me the xml encoding is ISO-8859-16 which means that the XMLDocument throws a XML Exception msg:unknown encoding ‘ISO-8859-16’.

Here is my code:
[i] Dim formtext as Text = “db=titles&code=2&line_1=Mas?: TakeAway&line_2=Osp?tar: MANAGER&line_3”
Dim postData as xojo.Core.MemoryBlock = xojo.Core.TextEncoding.UTF8.ConvertTextToData(formtext)

cSocket1.SetRequestContent(postData, “application/x-www-form-urlencoded”)
Dim lvS as String =“Basic “+ EncodeBase64(tfusername.Text+”:”+tfPassword.Text)
cSocket1.RequestHeader(“Authorization”) = lvS.ToText
cSocket1.RequestHeader(“Content-type”) = “application/x-www-form-urlencoded”

cSocket1.status = 0
cSocket1.username = tfusername.Text
cSocket1.password = tfPassword.Text
cSocket1.Send(“POST”,App.ivEpsonUrl.ToText+"/db_otf_xml.xml") //DEV[/i]

I have tried to use
Dim postData as xojo.Core.MemoryBlock = formtextxojo.Core.TextEncoding.FromIANAName(“ISO-8859-16”).ConvertTextToData(formtext)
but it throws the error “The text could not be represented in this encoding”

Does anyone has a clue on how to deal with this situation?

Thank you in advance.

Hi Sebastian,

Did you tried the MacRomanian on the encodings side ?

[quote=390063:@Sebastian Kapellas]
Dim postData as xojo.Core.MemoryBlock = xojo.Core.TextEncoding.UTF8.ConvertTextToData(formtext)[/quote]
This looks like the first problem. You said they expect one encoding, yet you’re using another to send data.

My problem is that i have a textarea where i type a text, for example Mas?:TakeAway&line_2=Osp?tar: MANAGER.
This one is UTF-8 Encoding.
I want this text to be converted to Windows-1250 or ISO-8859-16 encoding and then send it through xojo.net.httpSocket.

How can i do that?

You can use this (I’m using your example as source)

Dim t As Text=“Mas?:TakeAway&line_2=Osp?tar: MANAGER”
Dim m As Xojo.Core.MemoryBlock=xojo.Core.TextEncoding.FromIANAName(“ISO-8859-16”).ConvertTextToData(t)

Now if you look into the debugger m has the right text (for example ? is E3)

@Antonio Rinaldi
I have a RunTime Exception here.
Dim m As Xojo.Core.MemoryBlock=xojo.Core.TextEncoding.FromIANAName(“ISO-8859-16”).ConvertTextToData(t)

Message = “Invalid encoding name”

Once you converted text to UTF-8 string, you need to remove the encoding marker in the XML before giving it to the parser.
String is than UTF-8, so header should say UTF-8 or nothing.

Ok, I tried on macOS and there that encoding exists.

try:
Dim m As Xojo.Core.MemoryBlock=Xojo.Core.TextEncoding.FromIANAName(“Windows-1250”).ConvertTextToData(t)

Tried on win10 and works (same result)

@Antonio Rinaldi
I keep receiving runtime exception: This text could not be represented in this encoding.

At which stage?
the text you posted was:

[quote=390087:@Sebastian Kapellas]My problem is that i have a textarea where i type a text, for example Mas?:TakeAway&line_2=Osp?tar: MANAGER.
This one is UTF-8 Encoding.
I want this text to be converted to Windows-1250 or ISO-8859-16 encoding and then send it through xojo.net.httpSocket.

How can i do that?[/quote]
So you can do:
dim t as text=myTextArea.text.toText

check the content of your t variable and it should be: Mas?:TakeAway&line_2=Osp?tar: MANAGER

now you can convert it to a Xojo.Core.MemoryBlock with:
Dim m As Xojo.Core.MemoryBlock=Xojo.Core.TextEncoding.FromIANAName(“Windows-1250”).ConvertTextToData(t)

(tried on win10 and works)

Now you can use this m as the content of your Xojo.Net.HTTPSocket

I finally succeeded in sending the correct encoding and taking the correct answer using xojo 2016.r3.

Because here in Greece many restaurant continue using Windows Xp in their old touch Pc and we are stuck in Xojo 2015 for our Rest Project i did all my tests in this version. Xojo 15 support windows Xp but it does not have all the encodings support as it seems.

When i tried the same code in Xojo 2016.r3 everything worked correct.
Thank you everyone for your advice.
Have a nice weekend.