Nsmutableurlrequest Timeout Interval Not Taken into Consideration for Post Requests

NSMutableURLRequest not obeying my timeoutInterval

There's a thread on Apple dev forums discussing this issue. Apparently on iPhone OS, the setter mandates timeoutInterval a minimum of 240 seconds (4 minutes). This only occurs when the postBody is not empty (typically when using a POST request). This seems crazy, but apparently it's there to make sure requests leave the system even though it might take many seconds for the WWAN (3G) interface to wake up. 240 seconds seems rather steep, so they suggest to set a timer and cancel the asynchronous connection when your timer fires. I know this seems stupid, but that's the only I managed to get timeout for POST requests... :-(

Asynchronous request timeout interval never stop

According to another question here on Stackoverflow, the default timeout for POST is 240 seconds and any shorter intervals are ignored.

Link to answer here

Set the timeOut value for NSMutableURLRequest

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.

Request Timeout NSURLSession

You can't modify your request because for some reason you went with immutable option. Since NSMutableURLRequest is a subclass of NSURLRequest you can use the very same initializer init(URL:cachePolicy:timeoutInterval:) to create an mutable instance and set default timeout. And then configure (mutate) this request as you need.

let request = NSMutableURLRequest(URL: url!, cachePolicy: .ReloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 5.0)

NSURLConnection Taking Too long time

Use sendAsynchronousRequest to avoid hanging your UI and set the timeout Interval if you URL taking too long time.

[NSMutableURLRequest setTimeoutInterval:10.0f];

Hope it cures....:)



Related Topics



Leave a reply



Submit