iOS11 HTTP load failed (error code: -999)
app所有请求都返回 : Domain:NSURLErrorDomain Code=-999 “已取消”
可能是HTTPS的证书问题导致的。
解决方法:
对AFN请求类设置,不允许证书验证:
AFHTTPSessionManager *sessionManager = [[AFHTTPSessionManager manager]initWithBaseURL:nil]; _sessionManager.requestSerializer.timeoutInterval = HKNetworkTimeoutSeconds;//设置超时时间 _sessionManager.requestSerializer = [AFHTTPRequestSerializer serializer]; _sessionManager.responseSerializer = [AFHTTPResponseSerializer serializer]; _sessionManager.operationQueue.maxConcurrentOperationCount = 10;//设置最大线程数 // 1.设置非校验证书模式 _sessionManager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; _sessionManager.securityPolicy.allowInvalidCertificates = YES; [_sessionManager.securityPolicy setValidatesDomainName:NO]; // 2.使用证书模式 //NSString * cerPath = [[NSBundle mainBundle] pathForResource:@"xbapi.miguxue.com" ofType:@"cer"]; //NSData * cerData = [NSData dataWithContentsOfFile:cerPath]; //_sessionManager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate withPinnedCertificates:[[NSSet alloc] initWithObjects:cerData, nil]]; //_sessionManager.securityPolicy.allowInvalidCertificates = YES; //[_sessionManager.securityPolicy setValidatesDomainName:YES];