2010-01-01 128 views

回答

2

的默認請求超時爲60秒,但你可以改變它的任何的URLRequest。在本例中,我通過調用setTimeoutInterval將NSMutableURLRequest的超時設置爲15秒:

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];