A backend API I need to connect to takes about 3-4 minutes to return a response. The iOS client seems to timeout at exactly 60 seconds (which is the default), and I can't figure out how to extend that time out.
I have tried to set the timeoutInterval for the NSURLRequest to a large number, and set the Connection: Keep-Alive header, but I have no luck. Here is the code I am using, omitting some API details:
NSURL *url = [NSURL URLWithString:@"myAPI"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
NSString *postString = @"key1=val1&key2=val2...";
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
request.timeoutInterval = 600.0f;
[request setValue:@"Keep-Alive" forHTTPHeaderField:@"Connection"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSLog(@"data = %@", data);
}];
No data is returned and all response header fields are empty, even though the backend API is still processing the request.
I heard I might need to set something called a "socketTimout" interval so the socket knows to keep the connection open longer, but I do not know where to set that.