1

I user AF to send https request like

    [self.manager POST:downloadURLStirng parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success)
            success(responseObject,passParameters);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if(failure)
            failure(operation.responseObject,error,passParameters);
    }];

and i have already set securityPolicy to YES

    self.manager.requestSerializer = [AFJSONRequestSerializer serializer];
self.manager.securityPolicy.allowInvalidCertificates = OPENSSL;

but i still got code -1012 and error_message : In order to validate a domain name for self signed certificates, you MUST use pinning.

Allan
  • 2,086
  • 1
  • 18
  • 39
  • possible duplicate of [Problems with SSL Pinning and AFNetworking 2.5.0 (NSURLErrorDomain error -1012.)](http://stackoverflow.com/questions/27808249/problems-with-ssl-pinning-and-afnetworking-2-5-0-nsurlerrordomain-error-1012) – gran33 Aug 25 '15 at 07:47

2 Answers2

1

This is sets security policy to allow invalid certificates and stops domain name validation also.:

AFSecurityPolicy *securityPolicy = [AFSecurityPolicy 
policyWithPinningMode:AFSSLPinningModeNone];
securityPolicy.allowInvalidCertificates = YES;

[securityPolicy setValidatesDomainName:NO];
GSL
  • 23
  • 4
-4

I searched for this line

'NSLog(@"In order to validate a domain name for self signed certificates, you MUST use pinning.");'

and below this line I changed

'return NO;'
to

'return YES;'

and it did the magic.

Thanks.

Naveed Rafi
  • 2,503
  • 5
  • 32
  • 40
  • This is working for me too but it is questionable if this is a good approach. Will give this a try first: http://stackoverflow.com/questions/27808249/problems-with-ssl-pinning-and-afnetworking-2-5-0-nsurlerrordomain-error-1012 – Rick Dec 17 '15 at 07:18
  • 1
    Rather allocate with: `[AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];` – Rick Dec 22 '15 at 09:38
  • Why did you do this? What problem did it solve, and what advantages did it introduce? – Ky - Apr 22 '21 at 16:43