AFNetworking Enable GZIP

11,054

Solution 1

AFAIK NSURLConnection uses gzip decompresson by default and AFNetworking builds on the top of NSURLConnection. So, you shouldn't have to enable it.

Solution 2

It seems you need to add a HTTP header :

[self setDefaultHeader:@"Accept-Encoding" value:@"gzip"]

To the AfNetworking HTTP client.

Share:
11,054
Alan
Author by

Alan

Updated on June 05, 2022

Comments

  • Alan
    Alan about 2 years

    I am looking on the AFNetworking site that GZIP compression is supported " Gzip decompression from server responses is already built into AFNetworking, as NSURLConnection will automatically decompress responses with the Content-Encoding: gzip HTTP header. " - AFNetworking FAQ

    How do I enable GZIP compression so I can pull data from the server compressed or is it already defaulting to this?

    Thanks!

  • Alan
    Alan almost 11 years
    so it's not enabled as default?
  • Thomas Decaux
    Thomas Decaux almost 11 years
    Run a Charles proxy and check ! I can say on my version of AFNetwork it was not.
  • Alan
    Alan almost 11 years
    Thank you for the information. I am not familiar with networking. Before i had "[self setDefaultHeader:@"Accept" value:@"application/json"];" Can I have both? It seems if I replace it with the code above, it causes the app to crash.
  • Thomas Decaux
    Thomas Decaux almost 11 years
    I am not sure Accept is a valid HTTP header, you can check with HTTP protocol documentation, I think "Accept-Content" is what you need here. Of course you can have both, check with CharlesProxy if the HTTP headers have been really sent by your application.
  • Opal
    Opal about 10 years
    "Accept" is valid HTTP header. It describes what data format client expects (JSON,XML). "Accept-Encoding" HTTP header describes how the data will be transported (gzipped, plain text) over the web.
  • Snowman
    Snowman almost 9 years
    Are we just going to take this guy's word for it? Please cite a source.
  • amar
    amar over 8 years
    @moby "this guy" took the pains to answer thank him and if you have doubt do your own research if it doesn't work down vote him till then take his word because this is SO not a court.
  • Beyond Chao
    Beyond Chao over 6 years
    How to get Response Data before compression? What layer does this decompression happen ?CFNetwork?