-(void)resquestWithPost:(NSDictionary*)params Path:(NSString*)path completionAction:(CompletionBlock)completionBlock error:(ErrorBlock)errorBlock
{
Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
if (networkStatus == NotReachable) {
KAlertView(@"Alert", @"There IS NO internet connection");
} else
{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.securityPolicy.allowInvalidCertificates = YES;
manager.responseSerializer = [AFJSONResponseSerializer serializer];
NSString *str_url=[NSString stringWithFormat:@"%@%@",KbaseURl,path];
[manager POST:[NSString stringWithFormat:@"%@%@",KbaseURl,path] parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSData *jsonData = [responseObject dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:true];
completionBlock(jsonData);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
errorBlock(error);
}];
}
}
这是产生错误
错误:错误域= NSURLErrorDomain代码= -1012“的操作
无法完成。 (NSURLErrorDomain错误-1012。)”
UserInfo = 0x8abf470 {
NSErrorFailingURLKey = ....... NSErrorFailingURLStringKey = ...... NSUnderlyingError = 0x8dafed0
“该操作无法完成。(kCFErrorDomainCFNetwork错误
-1012。)“}
最佳答案
尝试这个,
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[securityPolicy setValidatesDomainName:NO];
[securityPolicy setAllowInvalidCertificates:YES];
manager.securityPolicy = securityPolicy;
关于ios - 当我调用api时,我正在使用以下方法,请提供解决方案,我通过COCOAPOD安装Afnetwoking,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34129121/