Http 包头里面有个content-length,可以获取下载的资源包大小

NSDictionary *headerFieldsDic = request.responseHeaders;

包大小为:[headerFieldsDic[@"Content-Length"] longLongValue]

 

参考代码

- (void)connectionNSURLConnection *)connection didReceiveResponseNSURLResponse *)response{
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
    if(httpResponse && [httpResponse respondsToSelectorselector(allHeaderFields)]){
        NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
        
        total_ = [[httpResponseHeaderFields objectForKey"Content-Length"] longLongValue];
        
        //NSLog(@"%lld", total_);
    }
}

 

posted @ 2022-03-10 19:37  milaliu99  Views(245)  Comments(0)    收藏  举报