🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.internet.winsock
1 messages
1 total messages Started by Daniel “Ico” Layne Fri, 16 Feb 2024 11:32
Trying to download a file via https:
#1
Author: Daniel “Ico” Layne
Date: Fri, 16 Feb 2024 11:32
109 lines
4470 bytes
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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads