Objective-c Check file size from URL without downloading

前端 未结 2 568
忘了有多久
忘了有多久 2020-12-16 07:09

I need to check the size of file from a URL. I get the file size perfectly when downloading file with AFNetworking.

AFHTTPRequestOperation *operation = [clie         


        
2条回答
  •  -上瘾入骨i
    2020-12-16 07:25

    here is the code:

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:candidateURL];
                        [request setHTTPMethod:@"HEAD"];
    
                        AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
                        [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
                         {
                             NSLog(@"Content-lent: %lld", [operation.response expectedContentLength]);
    
                         } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                             NSLog(@"Error: %@", error);
                         }];
    

提交回复
热议问题