【问题标题】:Default timeout seconds for AFNetworking?AFNetworking 的默认超时秒数?
【发布时间】:2015-12-11 12:46:13
【问题描述】:

在我的项目中,我使用 AFNetworking 进行 Api 调用,如何确定 AFNetworking 的默认超时秒数。请提出建议。

【问题讨论】:

  • 并且展示您解决问题的尝试。
  • 默认超时秒数:60

标签: ios objective-c afnetworking nsurlconnection nsurl


【解决方案1】:

AFNetwork 的默认超时时间为 60 秒

超时间隔,以秒为单位。如果在连接过程中尝试 请求保持空闲的时间超过超时间隔,请求 被认为已经超时。默认超时间隔为 60 秒。

补充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
}];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-04
    • 2011-08-02
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多