I have a method that makes a connection to a RestFUL server and for that it uses the components TIdHttp, TIdConnectionIntercept and others created in runtime, so alright, the problem is that I need to get the return of the "OnReceive" event of the component TIdConnectionIntercept and I do not know how to do this, see the code:
procedure ConHttpThread;
var
IdHTTPLibSysLoc : TIdHTTP;
IdCookieManagerLibSysLoc : TIdCookieManager;
IdConnectionInterceptLibSysLoc : TIdConnectionIntercept;
AuthSSL : TIdSSLIOHandlerSocketOpenSSL;
IdLogDebug1Loc : TIdLogDebug;
sHtmlResp, sHtmlErro : String;
begin
AuthSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
IdLogDebug1Loc := TIdLogDebug.Create(nil);
IdCookieManagerLibSysLoc := TIdCookieManager.Create(nil);
IdConnectionInterceptLibSysLoc := TIdConnectionIntercept.Create;
IdConnectionInterceptLibSysLoc.Intercept := IdLogDebug1Loc;
IdConnectionInterceptLibSysLoc.OnReceive := IdConnectionInterceptLibSysLocReceive;
IdHTTPLibSysLoc := TIdHTTP.Create(nil);
try
sHtmlResp := IdHTTPLibSysLoc.Post(xUrlPost, paramsLog);
except
sHtmlErro := ''; //variável s do evento IdConnectionInterceptLibSysLocReceive
end;
IdHTTPLibSysLoc.Disconnect;
end;
Component event
procedure TFPrin.IdConnectionInterceptLibSysLocReceive(
ASender: TIdConnectionIntercept; var ABuffer: TIdBytes);
var
i: Integer;
s: String;
begin
s := '';
for i := Low(ABuffer) to High(ABuffer) do
s := s + UTF8Encode(chr(ABuffer[i]));
end;
The event is called when it does TidHttp.Post (), and when the server returns an error it goes straight to Except, I can not use a glogal variable because this main method is mult thread, some idea how to get the return after Post?
Thank you!