views:

4540

answers:

2

How would I accept a self-signed server certificate? Using the code below, I can only connect/authenticate after I accept the Server Cert using Safari.

  • (void)secure:(NSString *)username credentials:(NSString *)login { NSURLCredential *userCredentials = [NSURLCredential credentialWithUser:username password:login persistence: NSURLCredentialPersistenceForSession];

    NSURLProtectionSpace *space = [[NSURLProtectionSpace alloc] initWithHost:LIST_URL_HTTPS port:443 protocol:@"https" realm:@"Restricted Area" authenticationMethod:NSURLAuthenticationMethodHTTPBasic];

    [[NSURLCredentialStorage sharedCredentialStorage] setCredential:userCredentials forProtectionSpace:space];

    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:imageURL] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:30];

    NSURLResponse *response; NSError *error;

    NSData *returnData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];

}

A: 

Found Answer here:

link text

Thanks, All

Jordan
A: 

Hi Jordan, I'm too facing self signed certificate issue. How to solve this? I saw the "link text" URL. But I didn't understand how your problem (infact my probled) is solved. Can you explain me in detailed. --Satyam.

Satyam
Lookup + (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host{ return YES; // Or whatever logic}
Jordan