title: How do I ignore an "invalid" SSL certificate in Objective-C?
body: <p>Currently I have:</p>
  <pre><code>NSArray* array = [NSArray arrayWithObjects:@&quot;auth.login&quot;,@&quot;username&quot;,@&quot;password&quot;, nil];
  NSData* packed_array = [array messagePack];
  
  NSURL* url = [NSURL URLWithString:@&quot;https://192.168.1.149:3790/api/1.0&quot;];
  NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
  [request setHTTPMethod:@&quot;POST&quot;];
  
  //Previously the below had changed by hostname.
  //[request setValue:@&quot;RPC Server&quot; forHTTPHeaderField:@&quot;Host&quot;];
  
  [request setValue:@&quot;binary/message-pack&quot; forHTTPHeaderField:@&quot;Content-Type&quot;];
  [request setValue:[NSString stringWithFormat:@&quot;%d&quot;,[packed_array length]] forHTTPHeaderField:@&quot;Content-Length&quot;];
  [request setHTTPBody:packed_array];
  
  NSURLResponse *response;
  NSError *error;
  responseData = [NSMutableData dataWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error]];
  
  NSLog(@&quot;response data: %@&quot;,[responseData messagePackParse]);
  NSLog(@&quot;error: %@&quot;,error);
  - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
  NSLog(@&quot;called canAuthenticateAgainstProtectionSpace&quot;);
  return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];  
  }
  - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
  NSLog(@&quot;called didReceiveAuthenticationChallenge&quot;);
  [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];  
  }
  </code></pre>
  <p>Which returns <code>&quot;Error Domain=NSURLErrorDomain Code=-1202 &quot;The certificate for this server is invalid&quot;…</code>&quot;</p>
  <p>How should I be implementing the answer from <a href="https://stackoverflow.com/questions/933331/how-to-use-nsurlconnection-to-connect-with-ssl-for-an-untrusted-cert">this question</a> <strong>and</strong> getting data back?</p>