While trying to communicate with my HTTPS server, I encountered a problem when CDN (Cloudflare) was active.
Exception class EIdOSSLUnderlyingCryptoError with message ‘Error connecting with SSL.
error:14094438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error’.
error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error’.
I switched to TNetHTTPClient and it worked. Here is the code:
// TNetHTTPClient.
function GetToken(CONST URL: string; StatusInfo: TCallbackEvent = NIL): Boolean;
var
Response: string;
HTTPClient: TNetHTTPClient;
JsonRequest: TStringStream;
begin
Result := FALSE;
HTTPClient := NIL;
JsonRequest := NIL;
TRY
// Initialize TNetHTTPClient
HTTPClient := TNetHTTPClient.Create(nil);
HTTPClient.ContentType := 'application/json';
HTTPClient.Accept := 'application/json';
// Prepare JSON request
JsonRequest := TStringStream.Create('{"token"}', TEncoding.UTF8);
try
// Send POST request
Assert(URL <> '');
Response := HTTPClient.Post(URL, JsonRequest).ContentAsString;
except
on E: Exception do
begin
if Assigned(FStatusChanged)
then FStatusChanged(Self, 'Error during server request: ' + E.Message);
Exit;
end;
end;
etc
FINALLY
FreeAndNil(JsonRequest);
FreeAndNil(HTTPClient);
END;
end;