gpt4 book ai didi

ios - 如何在AFNetworking中使用AFHTTPClient设置超时间隔?

转载 作者:行者123 更新时间:2023-12-01 17:53:31 25 4
gpt4 key购买 nike

如何使用AFHttpClient设置时间间隔

   AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@""]];
[httpClient setParameterEncoding:AFJSONParameterEncoding];
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];

最佳答案

超时信息是您需要创建然后反馈给客户端的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
}];

关于ios - 如何在AFNetworking中使用AFHTTPClient设置超时间隔?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22666600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com