0

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

Perseus
  • 1,546
  • 4
  • 30
  • 55
  • Look at my answer it may help http://stackoverflow.com/questions/1466389/nsmutableurlrequest-timeout-interval-not-taken-into-consideration-for-post-reque/27962981#27962981 – Mina Fawzy Jan 15 '15 at 12:03

2 Answers2

0

Try moving the setTimeoutInterval BEFORE the setHTTPMethod:@"GET"

Leigh
  • 28,765
  • 10
  • 55
  • 103
  • 1
    The above sounds more like a [comment](http://stackoverflow.com/help/privileges/comment). If it was intended to be an answer, consider adding a bit more detail explaining how it solves the problem. – Leigh Jan 22 '15 at 17:17
-1

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.

Community
  • 1
  • 1
Ilians
  • 743
  • 7
  • 23
  • You should not use timer, see [comments and answer](http://stackoverflow.com/questions/8304560/how-to-set-a-timeout-with-afnetworking#comment12884403_8304560) by [@matt](http://stackoverflow.com/users/157142/mattt) (author of [AFNetworking](https://github.com/AFNetworking/AFNetworking)). – DanSkeel Jun 17 '15 at 05:58