Connection Time out in iphone for http requests
What is the connection time out in the case of iphones. How lon开发者_如何学编程g will the compiler wait for a response after a request have been made??
Using NSURLConnection, the timeout is set in the NSURLRequest, and the default in the NSMutableURLRequest request is 60 seconds, and can be changed using the setTimeoutInterval method.
http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableURLRequest_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableURLRequest/setTimeoutInterval:
The default request timeout is 60 seconds, but you can change it for any URLRequest. In this example, I set the timeout to 15 seconds on an NSMutableURLRequest by calling setTimeoutInterval:
NSURL *url = [[NSURL alloc] initWithString:@"http://someurl.com"];
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:url];
[urlRequest setTimeoutInterval:15.0];
NSError *error;
NSURLResponse *response;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
精彩评论