gpt4 book ai didi

ios - AFNetworking : The Operation couldn't completed.(NSURLErrorDomain error -1004)

转载 作者:行者123 更新时间:2023-12-03 08:55:24 33 4
gpt4 key购买 nike

一段时间后,我的服务器响应缓慢,我得到此消息作为响应,该操作无法完成。(NSURLErrorDomain错误-1004)

如何处理此类错误?

附言我为此使用AFNetworking。

最佳答案

您可以通过覆盖get/post方法来增加超时时间

以下是get方法的示例

- (AFHTTPRequestOperation *)GET:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
{
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"GET" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:nil];
[request setTimeoutInterval:ADD_YOUR_TIME_OUT_INTERVAL];
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
[self.operationQueue addOperation:operation];
return operation;
}

附言我在AFNetwork的早期版本中使用了这种方法,通过子类化 AFHTTPClient。我没有在新版本的 AFHTTPRequestOperationManager中对其进行测试。

这可能会有所帮助: https://stackoverflow.com/a/22666837/1292441

关于ios - AFNetworking : The Operation couldn't completed.(NSURLErrorDomain error -1004),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27352768/

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