【发布时间】:2015-11-09 11:47:06
【问题描述】:
无法下载文件 收到此错误“客户端在收到整个响应之前关闭连接” 我要下载的文件只有 266KB
for (NSString *downloadURL in arr) {
// NSString *downloadURL = [d objectForKey:@"url"];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"URL for downloading : %@",downloadURL);
NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString *documentsDirectory = [pathArray objectAtIndex:0];
NSString *downloadedZipPath = [documentsDirectory stringByAppendingPathComponent:TEMP_DICTIONARY];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:downloadURL]];
// [request addValue:@"bytes=x-" forHTTPHeaderField:@"Range"];
// [request setTimeoutInterval:20];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:downloadedZipPath append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];
});
试图增加 api 请求超时但仍然无法正常工作
【问题讨论】:
标签: ios objective-c afnetworking afnetworking-2