2

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....

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • any URL we can test? Disable the firewall & test again? – Raptor Oct 18 '11 at 06:48
  • See the answer on link below http://stackoverflow.com/questions/6609813/error-using-nsurlconnection – Minakshi Oct 18 '11 at 06:59
  • The same problem. Increasing of timeout interval doesn't help. This doesn't happen every time, but pretty often. Just for the sake of the experiment I hold two devices, both connected to the same wifi. I try to open the same URL in Safari. One device receives request, and other gets 'connection failed' every time. I know it sounds weird. – berec Jul 04 '13 at 19:35

2 Answers2

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

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

Community
  • 1
  • 1
alloc_iNit
  • 5,173
  • 2
  • 26
  • 54
  • 1
    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.... – Harsha Vardhan Pabbineedi Oct 19 '11 at 04:45
0

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?..

berec
  • 775
  • 10
  • 19
  • Here is another thread devoted to this problem: https://github.com/AFNetworking/AFNetworking/issues/564. – berec Jul 05 '13 at 12:06