NSMutableURLRequest "The request timed out" issue . .
Asked Answered
Y

3

3

I am trying to download data in my application by using the following code

NSURL *url = [NSURL URLWithString:@"my download url string"];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.f];

NSURLConnection * connection = [NSURLConnection connectionWithRequest:request delegate:self];

[connection start];

but the problem is some times i am getting the following error

Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x1d5be240 
{NSErrorFailingURLStringKey=http://dr282zn36sxxg.cloudfront.net/datastreams/f-
d%3Afc7f649e1e3ba58452f67e3fa1f66f69a15b96b3ea585c946e4fa854%2BEPUB%2BEPUB.1, 
NSErrorFailingURLKey=http://dr282zn36sxxg.cloudfront.net/datastreams/f-
d%3Afc7f649e1e3ba58452f67e3fa1f66f69a15b96b3ea585c946e4fa854%2BEPUB%2BEPUB.1, 
NSLocalizedDescription=The request timed out., NSUnderlyingError=0x1e1975b0 "The request 
timed out."}

so , can anybody suggest me how to solve this . . .

Younts answered 2/9, 2013 at 9:49 Comment(13)
what kind of data you're trying to download?Lamarre
@iOSCoder Take a look at the error message ;)Dimetric
@iOSCoder it's file with extension .epubYounts
I just tried it in the simulator and it's definitely workingDimetric
@riyaz It's a quite large file, so do you download it on Wifi or cellular?Dimetric
Hmm ... For me it is definitely working. Is the page available in your country? I don't know if the unavailability of the page would produce a time out but honestly I have no other guess right now :(Dimetric
@Dimetric i am able to download some data , even some times i can able to download complete file i.e around 20mb file. . . but some times i am getting this error during download. . .Younts
have you tried using blocks?Lamarre
@iOSCoder No . .i am not using blocks . .Is this error related to not using of blocks ?Younts
@riyaz No it's not. The way you're dealing with it is correct!Dimetric
@riyaz..no,just have a try with the below method...i strongly believe that its because of the spotty internet connection you are using...Lamarre
@iOSCoder k i will try . . .Younts
@iAppDeveloper Why would using AFNetworking solve hat issue? Regarding a specified timeoutInterval, both approaches MUST behave identical. Just curious.Goingover
E
4

Increase the timeout interval like 150 secs .

Engle answered 8/9, 2013 at 17:50 Comment(0)
L
1

Try using GCDs abstraction called [NSURLConnection sendAsynchronousRequest:queue:completionHandler::

EXAMPLE:

NSURL *url = [NSURL URLWithString:@"your_URL"];
NSURLRequest *myUrlRequest = [NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest: myUrlRequest queue: queue completionHandler: ^ (NSURLResponse *response, NSData *data, NSError *error)
{

    if ([data length] > 0 && error == nil)
        //doSomething With The data

    else if (error != nil && error.code == ERROR_CODE_TIMEOUT)
        //time out error

    else if (error != nil)
        //download error
}];

DOES IT MAKING ANY DIFFERENCE?

Lamarre answered 2/9, 2013 at 10:41 Comment(0)
S
0

The error message clearly states that the request has timed out - Get to a place you get better network speed or increase the request timeout, I see it as 60 now sometimes which may not be sufficient for image downloads.

Soviet answered 2/9, 2013 at 10:12 Comment(2)
It's not an image download ;)Dimetric
In the current NSURLConnection implementation, a timeout occurs when there was "timeoutInterval" seconds inactivity on the connection. That is, even when the data gets in slowly, it should not timeout when you get at least one byte every "timeoutInterval" seconds (60 seconds, as specified).Goingover

© 2022 - 2024 — McMap. All rights reserved.