我的应用程序中有几个Web服务调用。下面是我如何打电话给他们AFHTTPRequestOperation超时
+(void) login:(NSDictionary *) loginParams {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSString * URLString = [MPTLogin getLoginWSAddress];
AFHTTPClient* client = [[AFHTTPClient alloc]initWithBaseURL:[NSURL URLWithString:URLString]];
NSMutableURLRequest *request = [client requestWithMethod:@"POST"
path:URLString
parameters:loginParams];
AFHTTPRequestOperation* operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"didSuccessfullyAttemptLogin" object:nil userInfo:nil];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if ([operation.response statusCode] == 401)
[[NSNotificationCenter defaultCenter] postNotificationName:@"invalidUserNameOrPassword" object:self userInfo:nil];
else
[[NSNotificationCenter defaultCenter] postNotificationName:@"didFailedAttemptLogin" object:self userInfo:nil];
}];
[operation start];
}
的问题是,如果没有调用Web服务在5-15分钟的例子,接下来的Web服务进行调用超时。然后之后的任何通话只需要一秒钟的实例完成,直到几分钟内没有通话。然后同样的事情再次发生。
这只发生在设备上。模拟器很好。此外,这不是一个无线网络问题。我完全失去了如何调试这个。
更新:所以我检查了服务器日志和电话没有按时到达。 我也试过使用Charles Proxy。最奇怪的事情发生了。代理打开时,超时不会发生。事实上,这些电话几乎立即发生。但是当我脱掉代理时,同样的问题会发生。
更新:这不是一个wifi问题,因为我们已经在不同的设备,不同的wifi连接,在不同的状态尝试它。
更新所以我最终将超时设置为150秒。现在,我的超时时间较少,但问题是,每当我发生超时时,控制台都会花费60秒。此外,超时代码是-1001
什么例子VA提供loginParams和URLString?它使用代理但不工作没有代理?服务器能否将请求视为垃圾邮件请求?只是一个随机猜测。 – Ricky
loginParams是字典:@ {@“userName”:@“simpleString”,@“password”:@“smipleString”,@“deviceName”:@“Somestring_anInt”}; –
您设置的超时是在服务器端还是在NSMutableURLRequest上的timeoutInterval?如果是用于NSMutableURLRequest,那么150秒太长了。你可以截屏或粘贴超时错误日志吗? – Ricky