我们可以从http返回的response中拿到一些连接的信息。
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; if(httpResponse && [httpResponse respondsToSelector:@selector(allHeaderFields)]){ NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
//把获取的文件的大小,存储在Content-Length里面。
total_ = [[httpResponseHeaderFields objectForKey:@"Content-Length"] longLongValue]; //NSLog(@"%lld", total_); } } |