Vor einiger Zeit hatte ich das gleiche Problem.
Ich habe es mit
Indy (Delphi 10.3) folgendermaßen gelöst:
1. IdHTTP
2. IdCompressorZLib
3. IdCompressionIntercept (nicht getestet, ob diese
Indy-Komponente wirklich erforderlich ist)
Wichtig ist: GetPage
muss zweimal aufgerufen werden.
Delphi-Quellcode:
object IdHTTP1: TIdHTTP
Intercept = IdCompressionIntercept1
AllowCookies = True
HandleRedirects = True
ProxyParams.BasicAuthentication = False
ProxyParams.ProxyPort = 0
Request.ContentLength = -1
Request.ContentRangeEnd = -1
Request.ContentRangeStart = -1
Request.ContentRangeInstanceLength = -1
Request.Accept = '
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
Request.BasicAuthentication = False
Request.UserAgent = '
Mozilla/3.0 (compatible; Indy Library)'
Request.Ranges.Units = '
bytes'
Request.Ranges = <>
HTTPOptions = [hoForceEncodeParams]
Compressor = IdCompressorZLib1
Left = 16
Top = 8
end
object IdCompressorZLib1: TIdCompressorZLib
Left = 72
Top = 8
end
object IdCompressionIntercept1: TIdCompressionIntercept
CompressionLevel = 0
Left = 128
Top = 8
end
Delphi-Quellcode:
function GetPage(aURL, sFile:
string):
string;
const
HTTP_RESPONSE_OK = 200;
var
Response: TStringStream;
fehler:
string;
begin
Result := '
';
Response := TStringStream.Create('
');
try
Form1.IdHTTP1.Get(aURL, Response);
if Form1.IdHTTP1.ResponseCode = HTTP_RESPONSE_OK
then begin
Result := Response.DataString;
end else begin
fehler := '
ERROR: '+inttostr(Form1.IdHTTP1.ResponseCode)+'
'+Form1.IdHTTP1.ResponseText;
Response.WriteString(fehler);
end;
except
fehler := '
ERROR: '+inttostr(Form1.IdHTTP1.ResponseCode)+'
'+Form1.IdHTTP1.ResponseText;
Response.WriteString(fehler);
end;
Response.SaveToFile(sFile);
Response.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
GetPage(
URL,'
FileToSave.txt');
GetPage(
URL,'
FileToSave.txt');
end;