Search code examples
xcodetimeoutnsurlconnectionnsmutableurlrequest

Set the timeOut value for NSMutableURLRequest


I am trying to set the timeout value for the NSMutableURLRequest, and while debugging, I have checked that it is not working. Googled for 10 mins, and I have got the info that , the default timeout value is 240 . The following are the code which I am using right now, I guess I am missing somewhere, I want to know how to set the timeOut value for the NSMutableURLRequest

NSURL *url = [[NSURL alloc] initWithString:fURL];

_urlRequest = [[NSMutableURLRequest alloc] url];
[_urlRequest setHTTPMethod:@"GET"];
[_urlRequest setTimeoutInterval:120];

NSURLConnection*  _urlConnection = [[NSURLConnection alloc] initWithRequest:_urlRequest delegate: self];

I have tried using this too [_nsmURLRequest initWithURL:nsURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:120]; . It is not working. Any help will be thankful


Solution

  • According to this post the default timeout value (240) you mentioned is also the minimum value. You'll have to use another timer to cancel the request as described in the link.