错误:错误域= NSURLErrorDomain代码= -1001“请求超时。”

时间:2016-07-06 04:50:20

标签: ios

我正在使用Xcode 6.1,iOS 8.1中的应用程序;该应用程序工作完全正常,直到2天,但今天,当我执行它时,我在网络服务&错误打印在下面。

Error: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x7c6899b0 {NSErrorFailingURLStringKey=<URL>, NSErrorFailingURLKey=<URL>, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x7c688f60 "The request timed out."}

我曾使用AFNetworking 2.x和以下代码段进行网络通话:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes=[manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];

[manager POST:<URL>
   parameters:<parameters>
      success:^(AFHTTPRequestOperation *operation, id responseObject) {

          NSLog(@"JSON: %@", responseObject);
          NSError *error = nil;
          NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:&error];
          if (error) {
              NSLog(@"Error serializing %@", error);
          }
          NSLog(@"Dictionary %@", JSON);
          NSLog(@"Success");
      }
      failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@"Error: %@", error);
      }]; 
}

2 个答案:

答案 0 :(得分:2)

您可以设置请求的时间间隔

[manager.requestSerializer setTimeoutInterval:100];

答案 1 :(得分:-1)

您可以设置请求的时间间隔

[manager.requestSerializer setTimeoutInterval:150];

如果服务器在时间间隔60秒后给出响应,那么它是有用的。