美文网首页ios开发iOS 开发
AFN3.0两种网络请求超时方法

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

作者: SheamUs | 来源:发表于2016-09-17 10:29 被阅读2041次

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两种网络请求超时方法

本文链接:https://www.haomeiwen.com/subject/rxoiettx.html