Decode GZIP Content From The REST Client In Delphi XE7 Firemonkey On Android And IOS

Delphi XE7 Firemonkey REST Client Decode GZIP ContentIf you’re building any kind of mobile app with the TRESTClient that ships with Delphi XE7 Firemonkey you’ll want it to use a minimum amount of data. One place where you can really reduce the amount of data usage is to compress the data between your REST server and your REST client app. The TRESTClient component uses TIdHTTP (and the HTTP protocol) which supports GZIP for compression. By default compression is not enabled in TRESTClient. You can enable compression by setting the TRESTRequest property AcceptEncoding to ‘gzip, deflate’. However, once the server starts sending you GZIPed content you will have to decode it. If the server supports GZIP and it gzips the contents the TRESTResponse.ContentEncoding property will be ‘gzip’. You will need to decode the content yourself at this point. For you to decode the content you can use the TRESTResponse.RawBytes property to access the data for decoding. Load the contents of RawBytes into a TMemoryStream and then use TIdCompressorZlib.DecompressGZipStream() to decompress the data. I’ve included a code snippet below. It should work on Android, IOS, OSX, and Windows plus it should compile for Appmethod as well.

Head over to the Embarcadero docwiki and check out all of the REST components available in the REST.Client unit for Delphi XE7 Firemonkey.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Decode GZIP Content From The REST Client In Delphi XE7 Firemonkey On Android And IOS by Delphi XE5 XE6 XE7 XE8 10 Seattle Berlin Firemonkey, Delphi Android, Delphi IOS is licensed under a Creative Commons Attribution 4.0 International License.

3 Responses to Decode GZIP Content From The REST Client In Delphi XE7 Firemonkey On Android And IOS

  1. Pingback: Ten Tips For Building Stunning Professional Android Apps With Delphi XE7 Firemonkey | Delphi XE5 XE6 XE7 Firemonkey, Delphi Android, Delphi IOS

  2. Luis Felipe says:

    Hi,

    I’m trying to run this code in IOS, but it doesnt work.
    In XE7 running on win32 works fine, but on IOS i get a exception: Error on call to ZLib library function inflateInit2_.

    Can you help me?

  3. Pingback: Secure Your REST Client With SSL And GZIP Compression In Delphi XE8 Firemonkey On Android And IOS | Delphi XE5 XE6 XE7 XE8 Firemonkey, Delphi Android, Delphi IOS

Leave a Reply

Show Buttons
Hide Buttons
Read previous post:
Delphi XE7 Firemonkey HTML Viewer And Report Library Android IOS
Upgraded Native HTML Viewer Component For Delphi XE7 Firemonkey On Android And IOS

Developer Alexander Sviridenkov has upgraded his HTML Component Library and Report Creation Library with new features for Delphi XE7 Firemonkey....

Close