SamChen
SamChen

Reputation: 405

verify a SSL certificate in iOS

I created a WCF web service hosted using https, I need to access this service using iPhone application.
The service works fine I can retrieve the data using a browser. which in this case, I need to pre-approve the certificate("The certificate for this server is invalid")
But in the iPhone app, I couldn't make it work.
What I have done so far is:

     - (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
[[challenge sender]continueWithoutCredentialForAuthenticationChallenge:challenge];

}

    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@"%@",error.description);  }

the connection returns with error(says exactly what a browser says)
The request should return a string or something really simple.

How do I proceed at this point? Btw, I use iOS5.0 Thanks

Upvotes: 0

Views: 1157

Answers (1)

SamChen
SamChen

Reputation: 405

Found it, only need to add one more line into the connection willSendRequestForAuthenticationChallenge method

[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];

Upvotes: 2

Related Questions