Dushyant Bansal     About     Archive

Setting HTTP request timeout with AFNetworking

Chances are you must have experienced the need of setting timeout for an HTTP request. Most of the times, this need can be resolved by other means. AFNetworking has a timeout of 60 seconds, by default, for all HTTP requests. You must also be very careful in choosing whether to modify this default timeout. My advice would be to go through these discussions first:

There are genuine use-cases too which require modifying default timeout. For example, doing some operation at app launch time where you can live with http request failure but keeping user waiting due to poor network connectivity is not desirable.

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:ROOT_URL]];

[manager.requestSerializer setTimeoutInterval:DesiredHTTPRequestTimeout];
comments powered by Disqus