Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This will obviously only work if you have a non self-signed cert OR you add:</p> <p>#define _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_ to your pch file. If you are using cocoa pods for this you will likely need to subclass AFHTTPRequestOperation and implement:</p> <pre><code>- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { if ([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust]) { if ([self bypassSslCertValidation:protectionSpace]) return YES; else return [super connection:connection canAuthenticateAgainstProtectionSpace:protectionSpace]; } return [super connection:connection canAuthenticateAgainstProtectionSpace:protectionSpace]; } - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { if ([self bypassSslCertValidation:challenge.protectionSpace]) { [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; return; } else return [super connection:connection didReceiveAuthenticationChallenge:challenge]; return; } } - (BOOL) bypassSslCertValidation:(NSURLProtectionSpace *) protectionSpace { if (ENVIRONMENT_TYPE == DEV_ENV || ENVIRONMENT_TYPE == STAGING_ENV) { return YES; } return NO; } </code></pre> <p>Then tell AFNEtworking to use the new subclass:</p> <pre><code>AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@""]]; [client registerHTTPOperationClass:[YourSubClassHTTPRequestOperation class]]; </code></pre> <p>It's not the easiest thing to do in the world and technically ignoring self-signed isn't making it work, but if you use standard SLL certificates It's probable it will work just fine, remember to remove this code or make it only available when debugging if you plan to release.</p> <p>Adding to answer because comments have char limits!</p> <p>Few choices looking at the <a href="https://github.com/AFNetworking/AFNetworking/blob/master/AFNetworking/AFHTTPClient.h">headers</a></p> <p>Return operation that can be manually added to the queue:</p> <pre><code>- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest </code></pre> <p>Or pass in your custom subclass operation to this one:</p> <pre><code>- (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload