Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AFNetworking - get response content length

I am using a simple AFNetworking [AFHTTPRequestOperation -initWithRequest:] for downloading file, I would like to check for the response header "content length" before I can actually download the file. How can I check for response content length in AFNetworking ?

like image 940
code2kick Avatar asked Mar 03 '26 12:03

code2kick


1 Answers

Using expectedContentLength Property of NSURLResponse You can you can find length.

 AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    [op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         NSLog(@"Content-lent: %lld", [operation.response expectedContentLength]);

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];
like image 63
Toseef Khilji Avatar answered Mar 06 '26 02:03

Toseef Khilji



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!