3

我正在使用简单的 AFNetworking [AFHTTPRequestOperation -initWithRequest:] 下载文件,我想在实际下载文件之前检查响应头“内容长度”。如何在 AFNetworking 中检查响应内容长度?

4

1 回答 1

6

使用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);
    }];
于 2013-10-10T09:33:26.807 回答