iOS AFNetworking load failed with error Error Domain=NSURLErrorDomain Code=-1001 "The request ti问题解决

在使用 AFNetworking 进行服务器数据的请求时,出现了如下错误:

根据打印的错误信息,我们可以发现,这是网络请求超时引起的,所以对代码修改如下:

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 180;
    [manager GET:@"http://xxx" parameters:@{} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
    
         CRLog(responseObject);
       
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];

此时,我们便可以正常的获取数据。

你可能感兴趣的:(iOS AFNetworking load failed with error Error Domain=NSURLErrorDomain Code=-1001 "The request ti问题解决)