0

プロジェクトにRestKitを使用しています.10〜20分(600〜1200秒)のようなリクエストのタイムアウトが必要です。タイムアウトを1秒から60秒に変更でき、これは問題なく機能します。しかし、60 秒 (90-9999999) を超えて設定しようとすると、60 秒後にタイムアウト エラーが発生します。RKRequest.m にそのようなコードがあります:

- (void)fireAsynchronousRequest {
    RKLogDebug(@"Sending asynchronous %@ request to URL %@.", [self HTTPMethod], [[self URL] absoluteString]);
    if (![self prepareURLRequest]) {
        // TODO: Logging
        return;
    }
    _isLoading = YES;

    if ([self.delegate respondsToSelector:@selector(requestDidStartLoad:)]) {
        [self.delegate requestDidStartLoad:self];
    }

    RKResponse* response = [[[RKResponse alloc] initWithRequest:self] autorelease];

    _connection = [[NSURLConnection connectionWithRequest:_URLRequest delegate:response] retain];


    [[NSNotificationCenter defaultCenter] postNotificationName:RKRequestSentNotification object:self userInfo:nil];
}

NSURLConnection init の前に 1 行追加しました。

[_URLRequest setTimeoutInterval:1200];

しかし、60秒後に再びタイムアウトエラーを受け取りました。RKResponse オブジェクトは NSURLconnection のデリゲートです。そのため、60 秒後に RKResponce.m のデリゲート メソッドが呼び出されることがわかりました ([_URLRequest setTimeoutInterval:1200] の後に NSURLConnection オブジェクトを初期化しようとしても):

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    RKResponseIgnoreDelegateIfCancelled();
    _failureError = [error retain];
    NSLog(@"Error %@", error);
    [_request invalidateTimeoutTimer];
    [_request didFailLoadWithError:_failureError];
}

NSURLConnection のタイムアウトを 60 秒以上にできないのは、私にとって奇妙です。

今日、この問題をテストするために新しいプロジェクトを作成しました。私はこのコードを持っています:

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSURL *url = [NSURL URLWithString: @"http://5.9.10.68:8182"];
    NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:url];
    [urlRequest setHTTPMethod:@"GET"];
    [urlRequest setTimeoutInterval:300.0];
    NSLog(@"timeout %f",urlRequest.timeoutInterval);

    NSURLConnection*  urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate: self];

}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {

    NSLog(@"Error request %@", error);

}

だからここにログがあります:

2012-07-17 14:37:58.627 f[76799:f803] タイムアウト 300.000000
2012-07-17 14:39:14.488 f[76799:f803] エラー リクエスト エラー Domain=NSURLErrorDomain Code=-1001 「リクエストがタイムアウトしました。 " UserInfo=0x687a690 {NSErrorFailingURLStringKey=http://5.9.10.68:8182/, NSErrorFailingURLKey=http://5.9.10.68:8182/, NSLocalizedDescription=リクエストがタイムアウトしました., NSUnderlyingError=0x687a070 "リクエストがタイムアウトしました."}

したがって、タイムアウト = 75 ですが、300 ではありません。非常に奇妙です。

4

1 に答える 1

0

このようにしてみましたか?

RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURL:@"http://somewhere.com"];
objectManager.client.timeoutInterval = 600;
于 2012-07-16T19:23:11.500 に答える