(Gast)
n/a Beiträge
|
AW: Wo Programmupdate hinspeichern
17. Nov 2018, 18:11
An den Header kommt man sehr leicht heran, wenn man das richtig angeht. Hier mal ein kleines Beipiel, wie das prinzipiell gehen könnte:
Delphi-Quellcode:
uses
Winapi.ShellAPI,
Winapi.Windows,
System.Classes,
System.SysUtils,
System.Net.HttpClient;
procedure DownloadFile( const AUrl: string; const AMimeType: string; const AStream: TStream );
var
clt: THttpCLient;
response: IHTTPResponse;
begin
clt := THttpCLient.Create( );
try
response := clt.Get( AUrl );
if response.StatusCode = 200
then
begin
if response.MimeType = AMimeType
then
begin
AStream.CopyFrom( response.ContentStream, response.ContentLength );
end else if response.MimeType.StartsWith( ' text/html', true )
then
begin
ShellExecute( 0, ' open', PChar( AUrl ), nil, nil, SW_SHOW );
end
else
raise Exception.CreateFmt( ' Unexpected Content-Type %s', [response.MimeType] );
end
else
raise Exception.CreateFmt( ' Unexcepted StatusCode %d (%s)', [response.StatusCode, response.StatusText] );
finally
clt.Free( );
end;
end;
procedure Main;
var
stream: TMemoryStream;
begin
stream := TMemoryStream.Create;
try
DownloadFile( ' https://www.delphipraxis.net/attachments/50203d1541379986-kodezwergs-tinihelper-klasse-inihelper.7z', ' application/x-7z-compressed', stream );
WriteLn( stream.Size );
stream.Clear( );
DownloadFile( ' https://avm.de/fileadmin/user_upload/DE/Labor/Download/fritzbox-7590-labor-63282.zip', ' application/zip', stream );
WriteLn( stream.Size );
stream.Clear( );
finally
stream.Free;
end;
end;
|
|
Zitat
|