如何在AFNetworking中使用AFHTTPClient设置超时间隔? [英] How to set Timeout Interval with AFHTTPClient in AFNetworking?
本文介绍了如何在AFNetworking中使用AFHTTPClient设置超时间隔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用AFHttpClient设置时间间隔
How to set time interval with AFHttpClient
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@""]];
[httpClient setParameterEncoding:AFJSONParameterEncoding];
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
推荐答案
超时信息是<$ c的一部分$ c> NSURLRequest 您需要先创建然后将其提供给客户端:
The time out information is part of the NSURLRequest
that you need to create and then feed to the client:
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@""]];
[httpClient setParameterEncoding:AFJSONParameterEncoding];
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@""] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:10]; // <- 10 is the timeout interval
AFHTTPRequestOperation *op = [httpClient HTTPRequestOperationWithRequest:req success:^(AFHTTPRequestOperation *operation, id responseObject) {
// DONE
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// FAILED
}];
这篇关于如何在AFNetworking中使用AFHTTPClient设置超时间隔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文