Hi
Thanks for your response. I spend a few days to try to solve this big
problem for me ...
I done what you say, but still got exception ...
TSMSMobile is record ..
type THttpsThread_Telekom = class(TThread)
private
Cli: TSslHttpCli;
SslContextCli: TSslContext;
IcsLogger: TIcsLogger;
SslAvlSessionCache: TSslAvlSessionCache;
DB: TFDConnection;
tranDB: TFDTransaction;
...
procedure Execute; override;
procedure HttpsClientCreate;
procedure IcsLoggerIcsLogEvent(Sender: TObject; LogOption:
TLogOption; const Msg: string);
procedure HttpsClientDestroy;
procedure DoTelekomPostar(val: TSMSMobile);
function ParseSMSXmlBillingRequest(var val: TSMSMobile): boolean;
procedure DBCreate(dbPath:string; dbServer:string);
procedure DBDestroy;
public
constructor Create(val:TSMSMobile; dbPath:string; dbServer:string);
destructor Destroy; override;
end;
constructor THttpsThread_Telekom.Create(val: TSMSMobile; dbPath: string;
dbServer:string);
begin
inherited Create(True);
CopyTSMSMobile(FVal,Val);
FdbPath:=dbPath;
FdbServer:=dbServer;
FreeOnTerminate:=True;
end;
destructor THttpsThread_Telekom.Destroy;
begin
HttpsClientDestroy;
DBDestroy;
inherited;
end;
procedure THttpsThread_Telekom.Execute;
var
bEnd:boolean;
begin
inherited;
providerID:=FVal.id_provider;
DBCreate(FdbPath, FdbServer);
HttpsClientCreate;
PostData;
HttpsClientDestroy;
DBDestroy;
Terminate;
end;
procedure THttpsThread_Telekom.HttpsClientDestroy;
begin
FreeAndNil(Cli);
FreeAndNil(SslContextCli);
FreeAndNil(SslAvlSessionCache);
FreeAndNil(IcsLogger);
end;
procedure THttpsThread_Telekom.DBDestroy;
begin
FreeAndNil(DB);
FreeAndNil(tranDB);
end;
procedure THttpsThread_Telekom.DBCreate(dbPath:string; dbServer:string);
begin
DB := TFDConnection.Create(nil);
with DB do
begin
Name := 'DB';
Params.Clear;
Params.Add('Database='+dbPath);
Params.Add('Protocol=TCPIP');
Params.Add('Server='+dbServer);
Params.Add('Port=3050');
Params.Add('CharacterSet=WIN1250');
Params.Add('DriverID=FB');
LoginPrompt := False;
end;
tranDB := TFDTransaction.Create(nil);
with tranDB do
begin
Name := 'tranDB';
Connection := DB;
Options.Params.Add('read_committed');
Options.Params.Add('rec_version');
Options.Params.Add('nowait');
end;
DB.Transaction := tranDB;
end;
procedure THttpsThread_Telekom.HttpsClientCreate;
begin
IcsLogger := TIcsLogger.Create(nil);
with IcsLogger do
begin
LogFileName := 'Debug_Out_HttpsTst.txt';
LogOptions := [loDestEvent, loDestFile, loDestOutDebug, loAddStamp,
loWsockErr,
loWsockInfo, loWsockDump, loSslErr, loSslInfo,
loSslDump, loProtSpecErr,
loProtSpecInfo, loProtSpecDump];
OnIcsLogEvent := IcsLoggerIcsLogEvent;
end;
SslContextCli := TSslContext.Create(nil);
with SslContextCli do
begin
IcsLogger := IcsLogger;
SslVersionMethod := sslBestVer_CLIENT;
SslECDHMethod := sslECDH_P256;
end;
SslAvlSessionCache := TSslAvlSessionCache.Create(nil);
with SslAvlSessionCache do
begin
IcsLogger := IcsLogger;
end;
Cli := TSslHttpCli.Create(nil);
with Cli do
begin
MultiThreaded := true;
IcsLogger := IcsLogger;
Timeout := 10;
SslContext := SslContextCli;
OnBgException := SslHttpCliBgException;
OnRequestDone := SslHttpCliRequestDone;
CtrlSocket.OnBgException := BackgroundException;
end;
end;
function THttpsThread_Telekom.PostData:boolean;
var
s:string;
i:integer;
begin
try
try
s:= XML string ... ;
Cli.CtrlSocket.ResetSSL;
Cli.SslContext.DeInitContext;
Cli.SendStream:= TStringStream.Create(s);//Prepare send
stream
sRecData:=StrAlloc(MAX_LEN_XML);
Cli.RcvdStream := TStringStream.Create(sRecData);//Prepare
receive stream
PrepareCliTelekom(provider, val);
if not Cli.SslContext.IsCtxInitialized then Exit; { V8.01 }
Cli.Post;
except
on E:Exception do begin
...
Exit;
end;
end;
finally
if Assigned(Cli.SendStream) then begin
Cli.SendStream.Free;
Cli.SendStream := nil;
end;
if Assigned(Cli.RcvdStream) then begin
Cli.RcvdStream.Free;
Cli.RcvdStream := nil;
end;
end;
end;
procedure THttpsThread_Telekom.PrepareCliTelekom(provider:TProvider; var
val:TSMSMobile);
const
SocksLevelValues : array [0..2] of String = ('5', '4A', '4');
SslVersions : array [0..5] of TSslVersionMethod =
(sslBestVer_CLIENT,sslV2_CLIENT,sslV3_CLIENT,sslTLS_V1_CLIENT,sslTLS_V1_1_CLIENT,sslTLS_V1_2_CLIENT);
{ V8.01 }
begin
cli.ContentTypePost:= 'text/xml';
cli.RequestVer := '1.0';
cli.URL:= 'https://';
cli.SslContext.SslCertFile:= 'Path to Cert.pem';
cli.SslContext.SslPrivKeyFile:= 'Path to Cert.pem';
cli.SslContext.SslPassPhrase:= 'PASSWORD';
cli.SslContext.SslCAFile := '';