NSUrlRequest 超时错误
当我从后台打开应用程序时,我需要访问服务器来获取一些数据。当我这样做时,我收到如下警报:
“请求超时”(nserror 的本地化描述)
我使用 wifi,我的互联网以及我的服务器都很好。
这种情况不是每次都会发生,而是经常发生。这是我的代码:
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(互联网)都很好,它也会超时。?提前致谢....
When I open the app from background I need to hit server to get some data. When I'm doing so I am getting an alert as follows:
"Request timed out" (nserror's localised description)
I'm on wifi and my internet as well as my server are fine.
This is not happening every time but happening frequently. Here is my code:
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];
}
What am I doing wrong and how can I fix this?
NSURLRequest *lRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:link] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
even i've used the above line instead of
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:myUrlString]];
but found nothing different . Still my request is getting timed out. Why is it getting timed out even when my server aswell as wifi (internet) are fine.?? Thanks in Advance....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从这里您可以获得指导...NSURLConnection 超时?
From here you can get the guidance...NSURLConnection timeout?
如果您对服务器端有信心,那么它可能不是软件问题,而是特定于硬件的问题。当我的 iPod5 连接到家庭 WiFi 时,我经常遇到这个问题,尽管连接到同一 WiFi 的所有其他设备都很好。今天,我测试了通过另一个 wifi 在问题设备上连接到我的服务器 - 超时错误消失了。诡异的。你要给谁打电话?...
If you're confident of your server-side then it may be not a software, but a hardware-specific issue. I have this issue very often with my iPod5 connected to home wifi, despite all other devices connected to the same wifi are fine. Today I have tested connection to my server on problem device via another wifi - timeout errors were disappeared. Weird. Who you gonna call?..