我正在制作一个iPad应用程序并使用NSURlConnection
连接到我的一个Web服务以从服务器检索一些数据。我以这样的方式调用webservice,每次检索20条记录。
有时在10-12次调用NSURLConnection后,将调用DidFailWithError
委托。错误日志显示:
The Internet connection appears to be offline
我也有一个重试按钮。我继续重试,但它继续得到相同的错误并转到DidFailWithError
。
有人可以告诉我这是什么问题吗?
以下是我正在使用的代码:
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soap length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"get_all_user_groups" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soap dataUsingEncoding:NSUTF8StringEncoding]];
NSUrlConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];