连续进行“操作无法完成”递归POST后调用AFNetworking [英] Getting continous "The operation couldn’t be completed" after recursive POST call AFNetworking

查看:111
本文介绍了连续进行“操作无法完成”递归POST后调用AFNetworking的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以递归方式调用POST Json Web服务,以连续地将数据上载/下载到服务中,直到全部完成为止。可能有多达500-1000个请求。但是在使用了一段时间后,我一直低于错误。 -1012是我最常得到的。

I am calling POST Json webservice in recursive manner to continuously Upload/download data to service until all is completed. There could be as much as 500-1000 request. But after using for sometime i keep getting below errors. -1012 is most often i get.

Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x7ae056b0 {NSErrorFailingURLKey=https://api.XXX.com/XXX/XXX/, NSErrorFailingURLStringKey=https://api.XXX.com/XXX/XXX/}


Error: Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo=0x7ba8e5b0 {NSErrorFailingURLStringKey=, _kCFStreamErrorCodeKey=57, NSErrorFailingURLKey=, NSLocalizedDescription=The network connection was lost., _kCFStreamErrorDomainKey=1, NSUnderlyingError=0x7a6957e0 "The network connection was lost."}

我曾在以下文章中提到它仅在iOS8上发生,但我同时在iOS7和iOS8以及设备/模拟器和Wifi /局域网上使用

I had referred to below post which saying it happens on iOS8 only but i am getting on both iOS7 and iOS8 and on both Device/Simulator and Wifi/Lan

Error Domain = NSURLErrorDomain代码= -1005网络连接丢失。

下面是我在方法中的使用方式

Below is how i am using in method

-(void) callService {
    //counter list variable is already initialized earlier
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:   
         [NSURL URLWithString:@"https://url.com/url"]];
    NSDictionary *params = @{@"id": counter,
                     @"data": [list objectAtIndex:counter]};
    NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET"
    path:@"http://url.com/url/url1/" parameters:params];
    AFJSONResponseSerializer *operation = [[AFJSONResponseSerializer 
           alloc] initWithRequest:request];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation 
        *operation, id responseObject) {
        //Process Data
        counter++;
        [self callService];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
        counter++;
        if(error.code == -1012 || error.code == -1005) {
            [self performSelector:@selector(callService) withObject:nil 
              afterDelay:5];
        } else {
            [self callService];
        }
    }];
    [operation start];
} 

在这种情况下,即使从服务器端关闭连接也有帮助。

推荐答案

解决方案

升级到AFNetworking 2.5.3现在,我得到的错误代码非常少,如-1005,-1012 ...,并正确执行了后续请求。当前还使用Connection从服务器端关闭。
将尝试与此同时使用keep alive,并将分享我的观察结果。

Upgraded to AFNetworking 2.5.3 and now i am getting very less error code like -1005, -1012... and follow subsequent request are executed properly. Also currently using Connection close from server side. Will try to use keep alive along with this and will share my observations.

感谢Rob的建议。

这篇关于连续进行“操作无法完成”递归POST后调用AFNetworking的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆