Idhttp indy post, request (parameters) with utf-8

I am trying to send a request in utf-8, however the server receives it in Ascii.

Tried TstringList message format.

Tried a stream format

I tried to get TStringStream to have UTF8 encoding.

I tried updating indy to xe5 indy

Here is a sample code:

var
  server:TIdHttp;
  Parameters,response:TStringStream;
begin
  response := TStringStream.Create;
  Parameters := TStringSTream.create(UTF8String('param1=Value1&param2=عربي/عرب&param3=Value3'),TEncoding.UTF8);
  Server.Post(TIdURI.URLEncode('http://www.example.com/page.php'),Parameters,response);
end;

Arabic coding is now transmitted as Ascii in a network sniffer.

0060 d8 b9 d8 b1 d8 a8 d9 8a 2f d8 b9 d8 b1 d8 a8 26 ........ / ...... &

How can I get Indy Http id to pass request parameters in Utf-8, and not in Ascii?

+4
source share
1 answer

TStringStreamin D2009 + uses UnicodeStringand TEncoding-aware, why not create UTF8Stringit manually:

var
  server: TIdHttp;
  Parameters,response: TStringStream;
begin
  response := TStringStream.Create;
  Parameters := TStringStream.Create('param1=Value1&param2=عربي/عرب&param3=Value3', TEncoding.UTF8);
  Server.Post('http://www.example.com/page.php',Parameters,response);
end;

TStrings UTF-8:

var
  server: TIdHttp;
  Parameters: TStringList;
  Response: TStringStream;
begin
  response := TStringStream.Create;
  Parameters := TStringList.Create;
  Parameters.Add('param1=Value1');
  Parameters.Add('param2=عربي/عرب');
  Parameters.Add('param3=Value3');
  Server.Post('http://www.example.com/page.php',Parameters,response);
end;

, Post(), , UTF-8:

Server.Request.ContentType := 'application/x-www-form-urlencoded';
Server.Request.Charset := 'utf-8';
+12

All Articles