M
M
Maxim Anarchistov2015-11-01 22:05:12
Delphi
Maxim Anarchistov, 2015-11-01 22:05:12

How to set up correct Cyrillic output via IDHTTP?

Business in what:
I Use IdHTTP for return of values ​​on the server (XE8). When saving to the database, question marks are saved instead of Cyrillic characters.
1. Using AnsiToUtf8 (and similar ones) does nothing at all.
2. Using URLEncode (various variations) makes the string look like "%0F%0E%0B%0D%00%0F" but saves all sorts of nonsense in the database
2.5 Using the standard TIdURI.URLEncode makes the string look like "%0F%0E%0B% 0D%00%0F", and writes it to the database.
3. Using UTF8String is impossible when building the Android version of the application, but it also does not lead to anything, question marks remain.
4. Using WriteString when preparing a request (together with Post) changes the final value in the database, but Russian letters do not appear (option aoaeoaae). Remarkably, outputting data using WriteString works great.
5. When using StringStream and StringList, the result is similar to that of WriteString.
My server, so it is possible to change the encoding on the server. At the moment, the encoding on the server is UTF-8, on the intermediate file - UTF-8 without BOM.
What to do? How to deliver the Cyrillic alphabet to the database in the simplest way?
PS The issue is resolved: The version with TIdURI.URLEncode and rawurldecode() works on the server with PHP.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Anarchistov, 2016-12-21
@ozonar

TIdURI.URLEncode and rawurldecode() on the server with PHP.

S
svd71, 2015-11-01
@svd71

That is, you have a problem in the database connection about which there is not a word. Delivering Cyrillic in the simplest way is to set up the correct connection to the database. As a result, for all character fields, you should create descendants of TWideStringField or its analogue. Check your database connection settings. If the base is Interbase/Firebird, then it is sufficient to specify UTF8 in the connection parameter.
If you still have an ANSII-encoded base and a connection to it, then in the text field methods in the Get/PutRecord events, you need to use processing by the utf8encode/utf8decode methods.

Z
zed, 2015-11-02
@zedxxx

Using AnsiToUtf8 (and similar ones) does nothing at all.

Can you show us at least a line of code how you do it? It seems that you are not working with strings correctly. Plus, I absolutely do not understand how converting text to utf8 and transferring it over the network can lead to "nothing ".
It's generally meant to encode URLs, not data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question