Link to home
Start Free TrialLog in
Avatar of Davita0011
Davita0011

asked on

TIdHTTP and unicode characters

Hello. I need to post a data to a web site and get response from. The problem is that the response contains multilanguage characters and the site is using utf8 charset. I tried to read the data from a TMemoryStream to widestring but didn't work. maybe I'm missing something. So anyone please can give me a working solution?
Thanks
Avatar of Pierre Cornelius
Pierre Cornelius
Flag of South Africa image

can you attach the stream you are trying to read (Alternatively your post data and the website returning your stream)?
Avatar of Davita0011
Davita0011

ASKER

ok, here's a code snippet how I actually try to read the data. there may be a syntax error because I don't have the codes and delphi here (at work). the attached file contains the IdHTTP response buffer.
Var http: TIdHTTP;
    res: TMemoryStream;
    s: WideString;
begin
res := TMemoryStream.Create;
http := TIdHTTP.Create;
http.Connect(Host);
http.Post('Host', PostParams, Res);
Res.Read(s, Res.Size);
end;

Open in new window

index-1-.txt
What is the host and postParams?
host is magtifun.ge. postparams is a TStrings decendent. it's 'remember=1', 'user=myuser', 'passwd='mypwd'
but it has no importance. I get the response fine, it fills the memory stream. my question is how I can read from memorystream to widestring
Why are you trying to read to a widestring?

I can read your response just fine using:

procedure TForm1.Button1Click(Sender: TObject);
Var res: TMemoryStream;
    s: string;
begin
  res := TMemoryStream.Create;
  res.LoadFromFile('C:\Documents and Settings\PeeCee\Local Settings\Temp\index-1-.txt');
  try
    Res.Position:= 0;
    SetLength(s, Res.size);
    Res.Read(s[1], Res.Size);
    Memo1.Text:= s;
  finally
    res.Free;
  end;
end;

If you need to convert it to widestring, simply assign the string to a widestring var and delphi will take care of the conversion e.g.

var
  s: string;
  ws: widestring;
begin
  read value into s (as above);
  ws:= s;
...
Thx pierre, but the response contains some unicode characters which are lost when reading as string. :)
ASKER CERTIFIED SOLUTION
Avatar of Pierre Cornelius
Pierre Cornelius
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks, I will try it when i'll get home and let you know the answer :)
Did you come right?
Forced accept.

Computer101
EE Admin