【发布时间】:2015-02-23 12:32:47
【问题描述】:
我正在做一个简单的请求,以便下载 PDF 文件,然后将其写入文件路径。 一些 PDF 被定向到失败块。 我得到的错误代码是 200,错误描述是“传输关闭,还有 2231939 字节要读取”。 下面是代码sn-p。
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];
}];
【问题讨论】:
-
如果您的某些文件出现此问题,您的服务器可以重置连接吗?还有其他关于错误描述的信息吗?
标签: ios afnetworking afnetworking-2