我正在使用一个简单的 AFNetworking [AFHTTPRequestOperation -initWithRequest:] 下载文件,我想在实际下载文件之前检查响应 header “内容长度”。 我如何检查 AFNetworking 中的响应内容长度?
最佳答案
使用 NSURLResponse 的 expectedContentLength 属性你可以找到长度。
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);
}];
关于ios - AFNetworking - 获取响应内容长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19291542/