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.
Author by
Alan
Updated on June 05, 2022Comments
-
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 almost 11 yearsso it's not enabled as default?
-
Thomas Decaux almost 11 yearsRun a Charles proxy and check ! I can say on my version of AFNetwork it was not.
-
Alan almost 11 yearsThank 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 almost 11 yearsI 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 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 almost 9 yearsAre we just going to take this guy's word for it? Please cite a source.
-
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 over 6 yearsHow to get Response Data before compression? What layer does this decompression happen ?CFNetwork?