【发布时间】:2011-11-17 18:43:08
【问题描述】:
首先,如果我如下使用 NSURLReuqest(non mutable),则连接会根据设置的内容超时。 奇怪的是为什么 NSLog 总是读 0?
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 秒左右超时。甚至比默认的 60 秒还要长...
即使我删除了[self.requestURL setTimeoutInterval:20]; 行,连接仍然会在 75 秒时超时。
我试过了
self.requestURL = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:requestString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0] autorelease];
【问题讨论】:
标签: iphone nsmutableurlrequest