AFNetworking错误代码= -1005“网络连接丢失”
问题描述:
我做了一个全局方法来发布HTTP请求。我想要全局处理响应并在发生错误代码= -1005的情况下再次发出请求。我应该怎么做?AFNetworking错误代码= -1005“网络连接丢失”
我使用的代码是如下: -
- (void)callHTTPAPIForRequest:(NSDictionary *)request onServer:(NSString *)serverURL resultBlock:(void (^)(id))resultBlock failureBlock:(void (^)(NSError *error))failureBlock{
NSLog(@"%@", request);
[self POST: serverURL parameters:request success:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSDictionary *dicResponce =[APIHelper getDictionaryFromNSData:operation.responseData];
NSLog(@"dicResponce: %@", dicResponce);
//NSLog(@"responseObject: %@", responseObject);
NSLog(@"the header fields in the request are %@",[operation.response allHeaderFields]);
BlockSafeRun(resultBlock, dicResponce);
}failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Error::: %@", error);
BlockSafeRun(failureBlock, error);
//failure(error);
}];
}
blockSafeRun定义如下宏: -
限定BlockSafeRun(块,...)块?块(VA_ARGS):无
请建议。 在此先感谢。
答
检查错误代码
if(error.code==-1005)
不是重新拨打服务有更多的错误不只是-1005请在基础架构NSURLError.h文件,你会得到明确的想法。我在这里张贴一些错误从NSURLError.h
NS_ENUM(NSInteger)
{
NSURLErrorUnknown = -1,
NSURLErrorCancelled = -999,
NSURLErrorBadURL = -1000,
NSURLErrorTimedOut = -1001,
NSURLErrorUnsupportedURL = -1002,
NSURLErrorCannotFindHost = -1003,
NSURLErrorCannotConnectToHost = -1004,
NSURLErrorNetworkConnectionLost = -1005,
NSURLErrorDNSLookupFailed = -1006,
NSURLErrorHTTPTooManyRedirects = -1007,
NSURLErrorResourceUnavailable = -1008,
NSURLErrorNotConnectedToInternet = -1009,
NSURLErrorRedirectToNonExistentLocation = -1010,
NSURLErrorBadServerResponse = -1011,
NSURLErrorUserCancelledAuthentication = -1012,
NSURLErrorUserAuthenticationRequired = -1013,
NSURLErrorZeroByteResource = -1014,
NSURLErrorCannotDecodeRawData = -1015,
NSURLErrorCannotDecodeContentData = -1016,
NSURLErrorCannotParseResponse = -1017,
NSURLErrorAppTransportSecurityRequiresSecureConnection NS_ENUM_AVAILABLE(10_11, 9_0) = -1022,
NSURLErrorFileDoesNotExist = -1100,
NSURLErrorFileIsDirectory = -1101,
NSURLErrorNoPermissionsToReadFile = -1102,
NSURLErrorDataLengthExceedsMaximum NS_ENUM_AVAILABLE(10_5, 2_0) = -1103,
// SSL errors
NSURLErrorSecureConnectionFailed = -1200,
NSURLErrorServerCertificateHasBadDate = -1201,
NSURLErrorServerCertificateUntrusted = -1202,
NSURLErrorServerCertificateHasUnknownRoot = -1203,
NSURLErrorServerCertificateNotYetValid = -1204,
NSURLErrorClientCertificateRejected = -1205,
NSURLErrorClientCertificateRequired = -1206,
NSURLErrorCannotLoadFromNetwork = -2000,
// Download and file I/O errors
NSURLErrorCannotCreateFile = -3000,
NSURLErrorCannotOpenFile = -3001,
NSURLErrorCannotCloseFile = -3002,
NSURLErrorCannotWriteToFile = -3003,
NSURLErrorCannotRemoveFile = -3004,
NSURLErrorCannotMoveFile = -3005,
NSURLErrorDownloadDecodingFailedMidStream = -3006,
NSURLErrorDownloadDecodingFailedToComplete =-3007,
NSURLErrorInternationalRoamingOff NS_ENUM_AVAILABLE(10_7, 3_0) = -1018,
NSURLErrorCallIsActive NS_ENUM_AVAILABLE(10_7, 3_0) = -1019,
NSURLErrorDataNotAllowed NS_ENUM_AVAILABLE(10_7, 3_0) = -1020,
NSURLErrorRequestBodyStreamExhausted NS_ENUM_AVAILABLE(10_7, 3_0) = -1021,
NSURLErrorBackgroundSessionRequiresSharedContainer NS_ENUM_AVAILABLE(10_10, 8_0) = -995,
NSURLErrorBackgroundSessionInUseByAnotherProcess NS_ENUM_AVAILABLE(10_10, 8_0) = -996,
NSURLErrorBackgroundSessionWasDisconnected NS_ENUM_AVAILABLE(10_10, 8_0)= -997,
};
+0
我也知道这种比较的错误代码。问题是如何再次调用请求而没有递归问题? –
+0
如果服务成功执行,则失败时触发请求,否则将不会是递归。在某些请求之后,将一些计数置于失败区域以停止。 – Smile
Chechk错误代码,如果它是错误比再次触发请求像error.code == - 1005 – Smile
检查一次NSUrlError.h文件在基础框架工作。 – Smile