开发者

NSURLConnection and Content-Encoding

I have an NSURLConnection which is downloading a web page. I get the Content-Length which is much smaller than the actual size of the file.

I noticed that the header also says:

Content-Encoding:gzip

I guess the size returned by Content-Length is th开发者_如何学Ce compressed size, however the NSData returned by NSURLConnection has been decompressed.

Firstly does NSURLConnection automatically decompress it? And how do I get the length of either the uncompressed file (instead of Content-Length)


If you need a progress bar, why not try ASIHTTPRequest? It has a number of built in features that help manage a progress bar.


If what you're trying to do is make some sort of progress bar or progress indicator for an NSURLConnection download, try the below code. It works like a charm in a few of my apps.

- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {   
    // append the new data to receivedData (a global variable).
    [receivedData appendData:data];
    // calculate number of kilobytes
    int kb = [receivedData length] / 1024;
    // update a label, or some other visula thingy
    self.downloadProgressLabel.text = [NSString stringWithFormat:@"Downloaded\n%d kB", kb];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜