Segmentation fault in THTTPClient

  

I’m having a strange problem with the THTTPClient component on android. when I put a THTTPClient component in a data module and execute my code everything works perfectly, but if I create the component at runtime a segmentation fault (11) error occurs when I close the application. I am using thread to access my server. This error only occurs when I close the app. I am using Rad Studio 10.3.1.

LThread := TThread.CreateAnonymousThread(
procedure
var
pegar: THTTPClient;
ts : TStringlist;
liberado:string;
begin
try
pegar := THTTPClient.create;
ts := TStringlist.create;
pegar.Accept :=
‘text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8’;
pegar.AcceptLanguage :=
‘pt-BR,en-US;q=0.8,pt;q=0.5,en;q=0.3’;
pegar.ContentType := ‘application/x-www-form-urlencoded’;

ts.Add(’email=’ + username);
ts.Add(‘password=’ + senha);
liberado := pegar.Post(caminho_api +
‘authentication/login’, ts).ContentAsString(TEncoding.UTF8);
finally
ts.free;
pegar.free;
end;
end);
LThread.FreeOnTerminate := true;
LThread.OnTerminate:=terminate_autenticacao;
LThread.Start;

But if I put the component in a DataModule and do that other way, this error does not occur:

LThread := TThread.CreateAnonymousThread(
procedure
var
ts : TStringlist;
liberado:string;
begin
try
ts := TStringlist.create;
datamodule.pegar.Accept :=
‘text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8’;
datamodule.pegar.AcceptLanguage :=
‘pt-BR,en-US;q=0.8,pt;q=0.5,en;q=0.3’;
datamodule.pegar.ContentType := ‘application/x-www-form-urlencoded’;

ts.Add(’email=’ + username);
ts.Add(‘password=’ + senha);

liberado := datamodule.pegar.Post(caminho_api +
‘authentication/login’, ts).ContentAsString(TEncoding.UTF8);

finally
ts.free;
end;
end);
LThread.FreeOnTerminate := true;
LThread.OnTerminate:=terminate_autenticacao;
LThread.Start;

Comments are closed.