好吧,首先,如果我使用NSURLReuqest(不可变),如下所示,连接会根据设置的内容做相应的超时。 奇怪的是为什么NSLog总是读0?NSMutableURLRequest setTimeoutInterval问题
self.requestURL = [NSURLRequest requestWithURL:[NSURL URLWithString:requestString]cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
NSLog(@"request timeOutInterval:%d", self.requestURL.timeoutInterval); // always 0
接下来,我做了这样的事情,timeoutInterval没有设置。
self.requestURL = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:requestString]] autorelease];
[self.requestURL setTimeoutInterval:20];
NSLog(@"request timeOutInterval:%i", self.requestURL.timeoutInterval); // same thing always 0 here.
编辑。我现在使用%f来记录timeoutInterval属性,并且都读取20.000。但真正的问题是,为什么我的NSMutableURLRequest在到达timeoutInterval(20s)时没有触发- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
委托回调方法。相反,它只是在大约75年代才会超时。甚至比60s的默认时间更长...
即使我删除了[self.requestURL setTimeoutInterval:20];
行,连接仍然在75秒超时。
我已经试过
我看到,我使用POST方法。但它超过了75s而不是240。我想知道为什么苹果强制执行这个... –
不确定。但我更喜欢ASIHTTPRequest。它好多了。 – visakh7