Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AFNetworking 2.0 - unexpected NSURLErrorDomain error -1012

Tags:

We ran into the following issue with our app that uses AFNetworking 2.0. When using AFHTTPRequestOperationManager's GET method, we got an error NSURLErrorDomain code -1012. The request used HTTPS and the server does not require user authentication. The request never reached the server by the way.

We have run several tests and this is the first time the error was produced and we are wondering how this error can get produced because it does not seem relevant.

Setup of AFHTTPRequestOperationManager :

httpOperationManager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:          [NSURL URLWithString: HTTPS_URL)]];  httpOperationManager.responseSerializer =          [AFXMLParserResponseSerializer serializer];  [[AFNetworkActivityIndicatorManager sharedManager] setEnabled: YES]; 

GET REQUEST

AFHTTPRequestOperation *op =[httpOperationManager GET:          [NSString stringWithFormat:SOME_PATH]          parameters:nil          success:^(AFHTTPRequestOperation *operation, id responseObject) {              //code to setup NSXMLParser ...         }          failure: ^(AFHTTPRequestOperation *operation, NSError *error) {             NSLog(@"error %@", [error localizedDescription]);         }]; 
like image 397
Charis Avatar asked Mar 11 '14 18:03

Charis


1 Answers

I think you already solved the problem, but if you are trying to authenticate in a server that doesn't have a valid certificate you have to set YES for property allowInvalidCertificates in your AFHTTPRequestOperationManager object:

[yourManager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"your_username" password:@"your_password"]; [yourManager.securityPolicy setAllowInvalidCertificates:YES]; 

Also, as @a1phanumeric said, it can be necessary to include this line:

[yourManager.securityPolicy setValidatesDomainName:NO]; 

Cheers.

like image 77
reinaldoluckman Avatar answered Oct 02 '22 09:10

reinaldoluckman