Einzelnen Beitrag anzeigen

ing

Registriert seit: 17. Jun 2005
Ort: Ingolstadt
7 Beiträge
 
#17

AW: Download mit https in Delphi 5

  Alt 20. Feb 2020, 07:30
Hallo,
mit den Indy-Komponenten sollte das problemlos funktionieren:

Code:
unit HTTPS;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


uses IdHTTP,IdSSLOPENSSL,IdGlobal;

var Http: TidHTTP;
     HTTPError:string;
     SSLHandler:TIdSSLIOHandlerSocketOpenSSL;

procedure HTTPInit(UseSSL:Boolean;Timeout:Integer=2000);
begin
  HTTPError:='';
  if Http=nil then
    Http := TidHTTP.Create(Nil);

  if UseSSL then
  begin
    if SSLHandler=nil then
    begin
      SSLHandler:=TIdSSLIOHandlerSocketOpenSSL.Create;
      SSLHandler.MaxLineAction := maException;
      SSLHandler.SSLOptions.SSLVersions:=[sslvSSLv2, sslvSSLv23, sslvSSLv3, sslvTLSv1,sslvTLSv1_1,sslvTLSv1_2];
      SSLHandler.SSLOptions.Mode := sslmUnassigned;
      SSLHandler.SSLOptions.VerifyMode := [];
      SSLHandler.SSLOptions.VerifyDepth := 0;

    end;

    Http.IOHandler:= SSLHandler;
  end
  else
  begin
    Http.IOHandler:= NIL;
  end;

  Http.ReadTimeout:=Timeout;
end;

procedure HTTPClose;
begin
  if Http<>nil then
  begin
    Http.Free;
    HTTP:=nil;
  end;

  if SSLHandler<>nil then
  begin
    SSLHandler.Free;
    SSLHandler:=nil;
  end;
end;

function LoadURL(const url:string; Timeout:Integer=2000):string;
var UseSSL:Boolean;
begin
  HTTPError:='';
  if Http=nil then
    Http := TidHTTP.Create(Nil);

  UseSSL:=Uppercase(Copy(url,1,5))='HTTPS';

  HTTPInit(UseSSL, Timeout);

  Try
    result := Http.Get(url);
  except
    on e:Exception do
    begin
      Result:='';
      HTTPError:=e.Message;
    end;
  end;

  HTTPClose;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Text := LoadURL('https://www.delphipraxis.net');
end;

end.
  Mit Zitat antworten Zitat