如何使用AFHttpClient设置时间间隔
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@""]];
[httpClient setParameterEncoding:AFJSONParameterEncoding];
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
答案 0 :(得分:5)
超时信息是您需要创建然后提供给客户的NSURLRequest
的一部分:
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
}];