NSUrlRequest 超时错误

发布于 2024-12-10 05:18:57 字数 1142 浏览 0 评论 0原文

当我从后台打开应用程序时,我需要访问服务器来获取一些数据。当我这样做时,我收到如下警报:

“请求超时”(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

§对你不离不弃 2024-12-17 05:18:57
NSURLRequest *lRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:link] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];

从这里您可以获得指导...NSURLConnection 超时?

NSURLRequest *lRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:link] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];

From here you can get the guidance...NSURLConnection timeout?

錯遇了你 2024-12-17 05:18:57

如果您对服务器端有信心,那么它可能不是软件问题,而是特定于硬件的问题。当我的 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?..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文