好吧,首先,如果我使用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