E
E
Evgeny Ivanov2016-11-04 23:39:06
Delphi
Evgeny Ivanov, 2016-11-04 23:39:06

How to use Cyrillic in IdHTTP request parameters?

Delphi 7. The code only works with English urls. With Cyrillic causes an error.
What needs to be done to work with English and Cyrillic urls?

//Записать ответ от сервера в файл pharsed_data.txt'
procedure get_https_file_content_to_file(https_url:string);
var
IdHTTP1: TIdHTTP;
IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocket;
server_response:ansistring;
text_file: textfile;
begin
IdHTTP1.HandleRedirects:=true;
IdHTTP1.RedirectMaximum:=15;
IdHTTP1:=TIdHTTP.Create(nil);
IdSSLIOHandlerSocket1:=TIdSSLIOHandlerSocket.Create(IdHTTP1);
IdSSLIOHandlerSocket1.SSLOptions.Method := sslvTLSv1;
IdHTTP1.IOHandler:=IdSSLIOHandlerSocket1;
//В интернете советуют строчку ниже для url с русскими буквами но у IdHTTP нет DefStringEncoding
//IdHTTP1.IOHandler.DefStringEncoding := TEncoding.ANSI;
server_response:=IdHTTP1.Get(https_url);
assignfile(text_file, ExtractFilePath(Application.ExeName)+'data\pharsed_data.txt');
rewrite(text_file);
write(text_file, server_response);
closefile(text_file);
end;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2016-11-05
@logpol32

1. Understand what encoding the server is using (usually UTF-8).
2. For paths - to convert (Utf8Encode like). Don't forget that Delphi 7 is non-unicode out of the box.
3. For domain names - encode in PunyCode. This is already somehow - I think there are libraries, but definitely not in a box.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question