Now I know that xCode automatically does the GZip decomposition for you inside:
NSData *data = [NSData dataWithContentsOfURL:URL];
And it works if I point to the Gzip file on my server. But since my content is dynamic, I have a PHP script, and then create a gzip file like this:
$zp = gzopen($file, "r"); $data = gzread($zp, $filesize); gzclose($zp);
I encode my data with:
echo gzencode($data, 9);
With this, I add the following headers:
header("Content-Type: application/x-gzip"); header("Content-Encoding: gzip"); header("Accepts-Encoding: gzip");
When I look at the URL, my browser wants to download the file automatically, and I can unzip it on my Mac and view its contents. However, when I try to read it through xCode, it will not work.
NSData *data = [NSData dataWithContentsOfURL:URL]; NSString *content = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog (content);
Did I forget something?
iphone gzip nsdata
Mark
source share