I'm doing a simple request in order to download PDF files and then write it to the file path. Some of the PDF's are getting directed to the fail block. The error code I'm getting is 200 and the error description is "transfer closed with 2231939 bytes remaining to read". Below is the code snippet.
NSURLRequest *request = [NSURLRequest requestWithURL:url
cachePolicy:nil
timeoutInterval:120];
AFHTTPRequestOperation *downloadRequest = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[downloadRequest setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if (operation.response.statusCode != 200) {
NSLog(@"Error code(S): %d",[operation.response statusCode]);
}else{
NSData *data = [[NSData alloc] initWithData:responseObject];
[data writeToFile:filePath atomically:YES];
NSLog(@"successful download to %@", filePath);
[data release];
}
[self fetchComplete:operation type:type];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error code: %d",[operation.response statusCode]);
NSLog(@"error discreption: %@",[error localizedDescription]);
[self fetchFailed:operation];
}];