在我的项目中,我使用 AFNetworking 进行 Api 调用,如何确定 AFNetworking 的默认超时秒数。请提出建议。
最佳答案
AFNetwork
的默认超时为60 秒
The timeout interval, in seconds. If during a connection attempt the request remains idle for longer than the timeout interval, the request is considered to have timed out. The default timeout interval is 60 seconds.
附加 reference
如果你想减少超时
NSDictionary *params = @{@"par1": @"value1",
@"par2": @"value2"};
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setTimeoutInterval:25]; //Time out after 25 seconds
[manager POST:@"URL" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
//Success call back bock
NSLog(@"Request completed with response: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//Failure callback block. This block may be called due to time out or any other failure reason
}];
关于ios - AFNetworking 的默认超时秒数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32583052/