That's because you are doing something really strange in your HTTPS-component:
Look at the highlighted line.
function THTTPS.HTTP_Get(AURL: string; var AResponse: string; var AError: string; CertifPath: string = ''): boolean;
begin
Result := False;
with THTTPS.Create(nil) do
begin
_ClientCertificate := CertifPath;
if CertifPath <> '' then
OnGetSocketHandler := @SSLClientCertSetup;
try
AResponse := Get(AURL);
Result := True;
except
on E: Exception do
begin
AError := E.ClassName + '/' + E.Message;
end;
end;
FreeAndNil(self);
end;
end;
You are releasing the THTTPS itself. Not the instance you created above.
But why are you creating a duplicate of THTTPS in that function?
You didn't define HTTP_Get() as class function so there is no need to recreate a THTTPS-instance at that point because you are already IN such an instance.
So this should work:
function THTTPS.HTTP_Get(AURL: string; var AResponse: string; var AError: string; CertifPath: string = ''): boolean;
begin
Result := False;
_ClientCertificate := CertifPath;
if CertifPath <> '' then
OnGetSocketHandler := @SSLClientCertSetup;
try
AResponse := Get(AURL);
Result := True;
except
on E: Exception do
begin
AError := E.ClassName + '/' + E.Message;
end;
end;
end;
Also, I would wrap the creation of THTTPS in a try/finally
g:= THTTPS.Create(nil);
try
g.HTTP_Get(url, r, err);
finally
g.Free;
end;