0

i writed few day ago the question about "Delphi & Indy & utf8" who you are help me to resolved the charset codified in utf8, but sometime the same routine is used to access other www with other charset.

the routine is this (in delphi xe6):

var
  Web: TIdHTTP;
  ASito  : AnsiString;
  TStr   : TStringStream;
  hIOHand: TIdSSLIOHandlerSocketOpenSSL;
begin

  try
    Web := TIdHTTP.Create(nil);
    TStr := TStringStream.Create('',TEncoding.UTF8);
    hIOHand := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
    hIOHand.SSLOptions.SSLVersions := [sslvTLSv1,sslvTLSv1_1,sslvTLSv1_2,sslvSSLv23];
    Web.IOHandler := hIOHand;

    Web.Request.UserAgent := INET_USERAGENT;       //Custom user agent string
    Web.RedirectMaximum := INET_REDIRECT_MAX;      //Maximum redirects
    Web.HandleRedirects := INET_REDIRECT_MAX <> 0; //Handle redirects
    Web.ReadTimeOut := INET_TIMEOUT_SECS * 1000;   //Read timeout msec
    Web.ConnectTimeout := INET_TIMEOUT_SECS div 2 * 1000;

    try
      Web.Get(FUrl,TStr);
      Sito := TStr.DataString;
    except
      on e : exception do
        Sito := 'ERR: ' +FUrl+#32+e.Message;
    end
  finally
    EndTime := Now;
    TStr.Free;
    Web.Free;
    hIOHand.Free;
  end;

What is the method to define the charset code at one any www page? Some page who i access are in json (and i must use utf8 in this case). I tried more options… but i can't able to fine the correct solution.

thakyou all for the help!

ondertol
  • 67
  • 2
  • 10
  • I already addressed this in [my answer](https://stackoverflow.com/a/52804446/65863) to [your previous question](https://stackoverflow.com/questions/52800270/). Please go re-read it. The best option is to simply let `TIdHTTP.Get()` decode the data for you: `Sito := Web.Get(FUrl);` As the charset used to *typically* correct, but there are options available when you need to make adjustments manually (`OnHeadersAvailable`, etc) . – Remy Lebeau Oct 16 '18 at 16:07
  • perfect Remy… i had the solution under my nose and i don't had find it… :-) Now the routine is perfect! Thank you so much! – ondertol Oct 16 '18 at 20:24

0 Answers0