0

I have an iOS app where I use NSURLConnection to fetch some data. When I print the headers from the response, this is what I see:

"Content-Disposition" = "attachment;filename=test.txt.gz";
"Content-Encoding" = agzip;
"Content-Type" = "application/a-gzip";
Date = "Mon, 05 Nov 2012 22:18:23 GMT";
Server = "Apache-Coyote/1.1";
"Set-Cookie" = "JSESSIONID=3EBBF519202E16BEB1E79D12XXXXXXXXX; Path=/";
"Transfer-Encoding" = Identity;
filename = "test.txt.gz";

But, when I try to read the log the text file like this:

NSString *result = [[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding];
NSLog(@"%@",result);

I get null. I know the data is there because it spits out hex when I log it, and I know the call works because I have tested it in RESTClient. Any thoughts?

IluTov
  • 6,807
  • 6
  • 41
  • 103
user1007895
  • 3,925
  • 11
  • 41
  • 63

2 Answers2

0

If it's gzipped data, then it's not NSUTF8StringEncoded. Unzip your data before you try and convert it. (given that it really is a string after unzipping)

Owen Hartnett
  • 5,925
  • 2
  • 19
  • 35
0

I ended up using ASIHTTPRequest, it handles this seamlessly. http://allseeing-i.com/ASIHTTPRequest/How-to-use

user1007895
  • 3,925
  • 11
  • 41
  • 63
  • Only problem is that ASIHTTPRequest has stopped all work (last update was May 2011) and the site recommends NOT using for new projects... – Darren Ehlers Jul 31 '13 at 18:51