我正在连接到我自己的 Web 服务,我相信它会发回一个 gzip 压缩的响应,该响应由 AF Networking 库在后台解压缩。我已经验证了当接受编码 gzip 标头存在时,我的服务器正在发送压缩的数据,并且我已经验证了库正在发送此标头。
但是 _totalBytesRead 的值是解压后的总字节数。这是因为这个值是在解压缩之后还是我实际上没有得到压缩数据?如果是前者,在 iOS 端确认我正在压缩数据的最可靠方法是什么?
下面的代码:
NSString *absolutePath = @"http://example.com/webservice";
NSMutableURLRequest * request = [self requestWithMethod:@"GET" path:absolutePath parameters:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:tempFilePath append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//_totalBytesRead here equals size of uncompressed file/data
}