I have a function using TIdCompressorZLib and TIdHTTP, like this:
pegar := tidhttp.create(nil);
compressor := TIdCompressorZLib.create(pegar);
seguro := TIdSSLIOHandlerSocketOpenSSL.create(pegar);
pegar.compressor := compressor;
pegar.Request.UserAgent := UserAgent;
pegar.Request.Accept := '*/*';
pegar.Request.AcceptEncoding := 'gzip, deflate';
pegar.Request.AcceptLanguage := 'pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7';
pegar.HTTPOptions := [hoForceEncodeParams];
pegar.ReadTimeout := 60000;
pegar.ConnectTimeout := 60000;
pegar.HandleRedirects := true;
pegar.IOHandler := seguro;
pegar.CookieManager := cookm;
pagina := pegar.Get(proxima_pagina);
This code works fine when compiled for Windows, but not for Android. On Android, TIdCompressorZLib does not unpack the source, returning unreadable characters.
Is there any way to fix this? I'm using Delphi 10.3.
Get rid of the assignment of the
AcceptEncodingproperty. LetTIdHTTPhandle that internally for you based on the actual capabilities of theCompressor. You are explicitly granting permission to the HTTP server to send a compressed response even if theCompressoris not able to handle it (ie, ifCompressor.IsReadyis False).That being said, Indy accesses ZLib on non-Windows platforms using dynamic load libraries. In this case, the
libzdylib on 'Nix platforms (Android runs on top of Linux), which is likely not present in your Android project.Compressor.IsReadyreturns False if Indy can't load the ZLib library at runtime. So, make sure that dylib is present in your deployment. Indy has anIdZLibSetLibPath()function in theIdZLibHeadersunit if you need to specify the location of that file at runtime.