当我从后台打开应用程序时,我需要点击服务器获取一些数据。当我这样做时,我得到了如下警告:
“请求超时”(nserror的本地化描述)
我在无线上网,我的互联网和我的服务器都很好。
这种情况并不是每次都发生,而是经常发生。这是我的代码:
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:myUrlString]];
NSURLConnection *conn=[[NSURLConnection alloc]initWithRequest:request delegate:self]; //sending request for data self.dataConnection=conn; [conn release];
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error" message:@"Network Exception" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}我做错了什么,我怎么解决这个问题?
NSURLRequest *lRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:link] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0]; 就连我都用了上面的一行
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:myUrlString]]; 但没发现什么不同。不过,我的请求被取消了。为什么即使我的服务器和wifi (互联网)都很好,它也会被超时。?提前谢谢..。
发布于 2011-10-18 07:07:15
NSURLRequest *lRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:link] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];从这里你可以得到指导.NSURLConnection timeout?
发布于 2013-07-05 12:01:13
如果您对服务器端有信心,那么它可能不是一个软件,而是一个特定于硬件的问题。我经常有这个问题,我的iPod5连接到家庭wifi,尽管所有其他设备连接到同一个wifi是好的。今天,我在问题设备上测试了与服务器的连接,通过另一个wifi -超时错误消失了。真奇怪。你要打给谁?
https://stackoverflow.com/questions/7803385
复制相似问题