0

我正在创建 NSMutableRequest 并将数据添加到正文。下面是我如何做到这一点的例子:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:stringURL] 
                                                           cachePolicy:NSURLRequestReloadIgnoringLocalCacheData 
                                                       timeoutInterval:230.0];
    NSLog(@"Time out interval: %f", request.timeoutInterval); >> Output: 230

    [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];

    NSLog(@"Time out interval: %f", request.timeoutInterval); >> Output: 240
    [request setTimeoutInterval:230];
    NSLog(@"Time out interval: %f", request.timeoutInterval); >> Output: 240

创建后请求超时为230。设置body后为240。在我将其重置为230后。它仍然是240。除非我将它设置得更大,否则超时值不会改变?

有人知道为什么会这样吗?如何使超时间隔小于 240 秒?

4

1 回答 1

1

在 iOS 上,您不能以这种方式指定小于 240 秒的超时时间(因为 iPhone 可能在慢速连接上运行)。有关更多详细信息,请查看:https ://devforums.apple.com/message/108292#108292

如果你真的需要更短的超时时间,你可以使用 NSTimer。在这种情况下,请记住使用异步请求,这很容易被取消。

于 2012-02-06T22:22:12.433 回答