Daniel “Ico” Layne
unread,Feb 16, 2024, 6:32:53 AM2/16/24You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Trying to download a file via https
keep getting this error:
error:1408F10B:SSL routines:ssl3_get_record:wrong version number'.
Prozess httpsRequest.exe (10272)
I teted sslVersion and Method in all constellations but it doesent seem to work.
----
program HttpsHttpRequest;
{$APPTYPE CONSOLE}
uses
SysUtils, Classes, IdHTTP, IdComponent, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdStack, IdGlobal,
IdSSLOpenSSL in 'openssl\IdSSLOpenSSL.pas',
IdSSLOpenSSLHeaders in 'openssl\IdSSLOpenSSLHeaders.pas',
uOpenSLLExt in 'openssl\uOpenSLLExt.pas';
procedure DownloadFile(const AHost: string; APort: Integer; const ADocument: string;
const AOutFile: string; ADebug: Boolean);
var
_IdHTTP: TIdHTTP;
_SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
_FileStream: TFileStream;
_Url: string;
begin
try
_IdHTTP := TIdHTTP.Create(nil);
_IdHTTP.HandleRedirects := true;
_SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(_IdHTTP);
try
{$IFDEF DEBUG}
while True do begin
sleep(100);
end;
{$ENDIF}
_IdHTTP.IOHandler := _SSLHandler;
if ADebug then
Writeln('---------- Debug AN ----------');
_Url := 'https://' + AHost + ':' + IntToStr(APort) + ADocument;
Writeln('Versuche Download von: ', _Url);
_FileStream := TFileStream.Create(AOutFile, fmCreate);
try
try
_IdHTTP.Get(_Url, _FileStream);
except
on E: EIdOSSLUnderlyingCryptoError do begin
Writeln(E.Message + #13#10);
Writeln('Fehler beim Herunterladen über HTTPS. Versuche HTTP...');
_IdHTTP.IOHandler := nil; // Setze den SSL-Handler zurück
_IdHTTP.Get('http://' + AHost + ':' + IntToStr(APort) + ADocument, _FileStream);
Writeln('---------------------------------------------------------------------');
end;
end;
finally
_FileStream.Free;
end;
Writeln('Download erfolgreich. Gespeichert unter: ', ExtractFilePath(AOutFile));
finally
_SSLHandler.Free;
end;
except
on E: Exception do begin
Writeln('Fehler: ' + #13#10 + E.Message);
end;
end;
_IdHTTP.Free;
end;
var
_Host, _Document, _OutFile: string;
_Port: Integer;
_Debug: Boolean;
begin
try
if ParamCount <> 5 then begin
Writeln('Usage: HttpsHttpRequest host port document outfile debug');
Halt(1);
end;
_Host := ParamStr(1);
_Port := StrToInt(ParamStr(2));
_Document := ParamStr(3);
_OutFile := ParamStr(4);
_Debug := StrToBool(ParamStr(5));
DownloadFile(_Host, _Port, _Document, _OutFile, _Debug);
except
on E: Exception do begin
Writeln('Error: ' + E.Message);
Halt(1);
end;
end;
end.