4
我正在做一個簡單的請求,以下載PDF文件,然後將其寫入文件路徑。 一些PDF正被引導到失敗塊。 我收到的錯誤代碼是200,錯誤描述是「傳輸關閉,剩餘2231939字節要讀取」。 以下是代碼片段。PDF與AFNetworking 2.0下載
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];
}];
如果只有部分文件使這個問題,可能您的服務器可以重置連接?有沒有關於錯誤描述的其他信息? – kocakmstf 2015-02-25 11:33:02
檢查此問題http://stackoverflow.com/questions/1759956/curl-error-18-transfer-closed-with-outstanding-read-data-remaining – Mateusz 2015-02-25 12:14:49