Using gzcompress in PHP; need to be able to unpack iPhone

I am sure this is not too complicated (and I am surprised that I cannot understand), but here goes:

So. I use gzcompress () to compress JSON data in PHP, so I can send it to an iPhone app.

Some problems raise the question of how to unzip this data on iPhone (iOS).

Any thoughts? I am collecting data through NSMutableURLRequest.

Thanks!


The code making the request:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:theURL]]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

Response code processing:

 NSString *responseString = [[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] autorelease]; 

And on the PHP side:

 echo(gzcompress(json_encode($lines))); 

Thanks!!!

+4
source share
1 answer

This article assumes that NSMutableURLRequest supports unzipping gzip out of the box, but you need to add the Accept-Encoding: gzip header to the request.

Extension of your example:

 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:theURL]]; [request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

I would also recommend testing a PHP script with cURL to make sure it sends valid gzipped data.

+1
source

Source: https://habr.com/ru/post/1347294/


All Articles