AFNetworking - get the length of the response content

I use simple AFNetworking [AFHTTPRequestOperation -initWithRequest:] to upload a file, I would like to check the response header "content length" before I can upload the file. How to check length of response content in AFNetworking?

+4
source share
1 answer

Using expectedContentLength Property NSURLResponse You can find the 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);
    }];
+7
source

All Articles