我遇到網絡請求應該超時的問題,但該方法未被調用。請求如下:iPhone SDK:URL請求不會超時
#define kCONNECT_TIMEOUT 20.0
request = [NSMutableURLRequest requestWithURL: aUrl];
[request setHTTPMethod: @"POST"];
postData = [jsonData dataUsingEncoding:NSASCIIStringEncoding];
[request setHTTPBody:postData];
[request setValue:@"text/xml" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setCachePolicy:NSURLCacheStorageAllowed];
[request setTimeoutInterval:kCONNECT_TIMEOUT];
self.connection = [NSURLConnection connectionWithRequest:request delegate:self];
assert(self.connection != nil);
這應該得到一個回調
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)_error
但不顯示錯誤消息,4分鐘後。任何人都知道這可能是爲什麼?
重複http://stackoverflow.com/questions/1466389/nsmutableurlrequest-timeout-interval-not-taken-into-consideration-for-post-reques – KevinDTimm 2010-03-18 16:28:22
這個問題已在iOS 4的起 – Abhi 2012-02-16 13:48:53