AFN3.0两种网络请求超时方法

no1

NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; config.timeoutIntervalForRequest = 15.0; 

AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:config];

[manager POST:urlStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) { 

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {                     
 
 NSLog(@"POST请求错误 = %@", error);

 }];

no2

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

[manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];

manager.requestSerializer.timeoutInterval = 15.0f;

[manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];

[manager POST:urlStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

NSLog(@"POST请求错误 = %@", error);

}];

你可能感兴趣的:(AFN3.0两种网络请求超时方法)