I
I
Igor2019-07-14 14:04:03
Delphi
Igor, 2019-07-14 14:04:03

How to force the server to return content in the specified encoding?

Colleagues, welcome.

...
Result := '';
   uri := TURI.Create(FBaseUrl);
   uri.Path := url;

   http := THTTPClient.Create;
   http.ConnectionTimeout := 12000;
   http.AllowCookies := true;
   http.CookieManager := TCookieManager.Create;
   http.ContentType := 'text/html; charset=utf8';
   http.Accept := 'text/html';
   http.AcceptCharSet := 'utf8';
   http.AcceptLanguage := 'ru-RU,ru';
   http.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36';

   ResponseStream:= TStringStream.Create('', TEncoding.UTF8);
   ErrorCounter := 0;
   Reload:
   IsExcept:= false;
   try
     Response := http.Get(uri.ToString, ResponseStream);
     ResponseStream.SaveToFile('TMKCardLoader.html');   
     result := ResponseStream.DataString;
   except
      on E: Exception do
      begin
        OutputDebugString(Pwidechar(E.Message));
        Inc(ErrorCounter);
        IsExcept := true;
      end;
    end;
...

90% of all cases, the following exception occurs:
No mapping for the Unicode character exists in the target multi-byte code page
The remaining 10% have no complaints.
Questions:
Why does the server return the content as it swells to it?
How to achieve loading in the correct encoding?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Yanyshev, 2017-10-12
@lemonlimelike

For starters, at least on a local machine, you would learn how to set up lamp ;)
Was it a2enmod php7.0 ?
a2endites setting was?

D
Dmitry, 2017-10-12
@Tabletko

In your case, you need to go to ip_addres/test.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question