xcode NSUrlRequest 超时错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7803385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Timed out error for NSUrlRequest
提问by Harsha Vardhan Pabbineedi
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)
“请求超时”(nserror 的本地化描述)
I'm on wifi and my internet as well as my server are fine.
我在 wifi 上,我的互联网以及我的服务器都很好。
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....
但发现没什么不同。我的请求仍然超时。为什么即使我的服务器和 wifi(互联网)都很好,它也会超时。??提前致谢....
采纳答案by alloc_iNit
NSURLRequest *lRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:link] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
From here you can get the guidance...NSURLConnection timeout?
从这里你可以得到指导... NSURLConnection 超时?
回答by berec
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?..
如果您对服务器端有信心,那么它可能不是软件问题,而是特定于硬件的问题。我的 iPod5 连接到家庭 wifi 时经常遇到这个问题,尽管连接到同一个 wifi 的所有其他设备都很好。今天,我通过另一个 wifi 测试了与问题设备上服务器的连接 - 超时错误消失了。奇怪的。你要给谁打电话?..